Group Forums >> web developers and designers >> Exporting Data to PowerPoint from VB.NET Web Page
Exporting Data to PowerPoint from VB.NET Web Page
|
30 posts back to top |
Posted 7 months ago All, I have currently been assigned a project to take reports that I have generated and convert them to a power point slide with the push of one button on the Page itself. Does anyone have any advice on how to accomplish this task or where to look? I am using Visual Studio 2005 for this project.
Thanks in Advance James Cassidy |
|
Account Removed 0 posts back to top |
| Posted 7 months ago I have no clue, good luck. |
|
30 posts back to top |
| Posted 7 months ago Ok, So far I have narrowed it down to two possibilities. VSTO 2.0 which comes with Visual Studio 2005. 3.0 comes with Visual Studio 2008 and has web capabilities but I have 2005. Or the other possibility is an office COM. The only thing is I have not had to use COM references with a web page before. I will keep everyone posted on how all this pans out. Last resort is I will tell my boss to get me Visual Studio 2008. James Cassidy |
|
30 posts back to top |
| Posted 7 months ago It turns out that VSTO will do everything you want to do as far as Visual Studio projects and Office products. It works with both Web and Win32/64 apps. I am not sure yet how all of this is done but I will update as I learn more. =-) James |
|
Account Removed 0 posts back to top |
| Posted 7 months ago Thanks. I will have learned something new today, and I will fall asleep less dumb. |
|
30 posts back to top |
| Posted 7 months ago Update, In order for you to use VSTO you must have a form of Visual Studio with the capability to use C# or Visual Basic, and Office Professional 2003 to current. Both must be installed on the system before you take the last step of preparing your machine to use VSTO. The last step is you need to go to the Microsoft Download Page for the "Visual Studio Tools for Office". This is a 6MB file. When installed you will notice the "Visual Studio Tools for Office Sec...." on the load screen of Visual Studio. The URL for the download: If you do not have Office Pro 2003 to current you will absolutely have to use COM references and Macros. James
|
|
30 posts back to top |
| Posted 7 months ago Update, Imports System.IO.Packaging 'Will not load or does not have publick classes This import statement was anoying me as you can see from the comment following it. I spent 3 days trying to figure out how to get it to properly import. Here is the answer on how to import the System.IO.Package namespace. If you are doing a Win32 App go to Project > Add Reference... via the Project menu item at the top of the screen. If you are doing a Website go to Website > Add Reference... via the Website menu at the top of the screen. At this point make sure you have the .NET tab selected and look for the WindowsBase.dll and select it. If it is not there do the following. Go to the Browse Tab and browse to C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0 and select the WindowsBase.dll. This process is critical to using the VSTO code and for some reason it is assumed everywhere you go for information that this is common knowledge. This import statement will allow you to modify Office 2007 documents without ever actually opening them. This is done by accessing the XML files that make up the document. To view the XML files that make up the document make sure it is the 2007 document format. For example the PowerPoint 2003 extension is filename.ppt. What you want is filename.pptx. Take that file name and add .zip to it. Example: filename.pptx.zip. Then open the .zip folder and copy the files and past them outside the .zip file. Open Internet Explorer and go to the menu and select open. In the drop down box at the bottom of the browse window select all files. navigate to the unzipped folders and open any of the documents located within. There you go the XML documents making up the file. Now all that I need to learn now is the best way of updating those XML docs. =-) James |
|
30 posts back to top |
| Posted 7 months ago Update, Ok, I have cracked this egg wide open and now know how to modify slides from code on a VB.NET web page. Here is what you need to do. Import the following: Imports Microsoft.VisualBasic 'This import should already be in your class when you create it. Imports System.IO Imports System.IO.Packaging Imports System.Collections.Generic Imports System.Text Imports System.Linq Imports System.Xml Imports DocumentFormat.OpenXml Imports DocumentFormat.OpenXml.Presentation Imports DocumentFormat.OpenXml.Packaging When you import all of these you will see that some of them say they do not exist. You need to Reference the Following. Go to the menu and click Website > Add Reference. Add DocumentFormat.OpenXml. You will need to do as stated in the above post to reference the WindowBase.dll. Browes to the same area but instead pick the v3.5 folder and select all the .dll files to add to your project. You are now set to program for Office Documents. I am currently making a page that will accept requests from other pages to build documents. In the following Posts I will give the foundation code to accomplish certain tasks. James |
|
30 posts back to top |
| Posted 7 months ago Here is the code to replace a picture in a PowerPoint Slide: Public Sub PPTReplaceImageOnSlide(ByVal fileName As String, ByVal slideTitle As String, ByVal imagePath As String) ' Given a slide deck name and a slide title within the deck,
Const documentRelationshipType As String = _
Const presentationmlNamespace As String = _
Dim documentPart As PackagePart = Nothing
' Manage namespaces to perform Xml XPath queries.
Dim slidePart As PackagePart = Nothing
' Select each slide document part (slides/slideX.xml)
' Get the slide part from the package.
' Locate the slide title using XPath.
' Perform a case-insensitive comparison.
' Look through the slide's relationships to see if
' Create a part for the new image
'Now copy the bytes into the new part
' Create a relationship to the new part:
' Update the relationship in the slide XML:
' Delete the old relationship.
' Only update the first image you run across.
' Only update the first image you run across:
' Reset the stream, and save the slide XML back to its part.
' Only modify the first slide that matches the
End If
End Using
|
|
30 posts back to top |
| Posted 7 months ago Looks like the code may need to go though a bit of reformatting once you paste it in the editor. =-) James |
|
30 posts back to top |
| Posted 7 months ago Here is the code to insert a slide into a .pptx. I am currently working on the code to delete a slide from the presentation.
' Open the source document as read/write.
Using (presentationDoc) 'Pass the source document and the position and title of the slide to be inserted to the next method.
End Using End Sub Private Sub InsertNewSlide(ByVal presentationDocument As PresentationDocument, ByVal position As Integer, ByVal slideTitle As String)
Dim presentationPart As PresentationPart = presentationDocument.PresentationPart ' Verify that the presentation is not empty.
' Declare and instantiate a new slide.
' Construct the slide content.
nonVisualProperties.NonVisualDrawingProperties = New DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties()
nonVisualProperties.NonVisualGroupShapeDrawingProperties = New DocumentFormat.OpenXml.Presentation.NonVisualGroupShapeDrawingProperties()
' Specify the group shape properties of the new slide.
' Specify the required shape properties for the title shape. Dim nvdpNonVisualDrawingProperties As New DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties()
Dim slShapeLocks As New Drawing.ShapeLocks()
Dim psPlaceholderShape As New PlaceholderShape()
titleShape.NonVisualShapeProperties = New DocumentFormat.OpenXml.Presentation.NonVisualShapeProperties(nvdpNonVisualDrawingProperties, New DocumentFormat.OpenXml.Presentation.NonVisualShapeDrawingProperties(slShapeLocks), New AppNonVisualDrawingProperties(psPlaceholderShape)) titleShape.ShapeProperties = New DocumentFormat.OpenXml.Presentation.ShapeProperties() Dim dtDrawingText As New Drawing.Text()
' Specify the text of the title shape.
' Declare and instantiate the body shape of the new slide.
' Specify the required shape properties for the body shape.
Dim slShapeLocks2 As New Drawing.ShapeLocks()
Dim psPlaceHolderShape2 As New PlaceholderShape()
bodyShape.NonVisualShapeProperties = New NonVisualShapeProperties(nvdp, New NonVisualShapeProperties(slShapeLocks2), New AppNonVisualDrawingProperties(psPlaceHolderShape2)) bodyShape.ShapeProperties = New ShapeProperties() ' Specify the text of the body shape.
' Save the new slide part.
' Modify the slide ID list in the presentation part.
' Find the highest slide ID in the current list.
For Each slideId As SlideId In slideIdList.ChildElements
maxSlideId = (maxSlideId + 1) ' Get the ID of the previous slide.
If (Not prevSlideId Is Nothing) Then
' Use the same slide layout as that of the previous slide.
' Insert the new slide into the slide list after the previous slide.
' Save the modified prsentation.
End Sub
|
|
30 posts back to top |
| Posted 7 months ago Here is the code to delete a slide from a .pptx presentation. Public Sub DeleteSlide(ByVal presentationFile As String, ByVal slideIndex As Integer) ' Open the source document as read/write.
Using (presentationDoc) ' Pass the source document and the index of the slide to be deleted to the next DeleteSlide method.
End Using End Sub Private Sub DeleteSlide(ByVal presentationDocument As PresentationDocument, ByVal slideIndex As Integer)
' Use the CountSlides code example to get the number of slides in the presentation.
' Get the presentation part from the presentation document.
' Get the presentation from the presentation part.
' Get the list of slide IDs in the presentation.
' Get the slide ID of the specified slide.
' Get the relationship ID of the specified slide.
' Remove the slide from the slide list.
' Remove references to the slide from all custom shows.
' Iterate through the list of custom shows.
If (Not (customShow.SlideList) Is Nothing) Then ' Declare a linked list.
' Iterate through all the slides in the custom show.
' Find the slide reference to be removed from the custom show.
' Add that slide reference to the end of the linked list.
' Remove references to the slide from the custom show.
' Save the change to the presentation part.
' Get the slide part for the specified slide.
' Remove the slide part.
End Sub
|
|
30 posts back to top |
| Posted 7 months ago Anyone that is interested on learning more about this topic or has some insight into this topic please sign up for my new group "Office Open XML Development". Thanks James
|

