I am attempting to develope classes that are dedicated to each office document. With this class I will have it passed information from the database of stored procedure names and format information. When the user presses a button the document information for the report they want will be sent to this class creating a document with up to date information. Only one problem. I am for some reason not able to figure out how to add children nodes to a document. Here is a function that I have been working on.
Public
Function PPTInsertNewSlide(ByVal fileName As String, ByVal position As Integer, ByVal title As String) As Boolean
Dim returnValue As Boolean = False
Dim documentPart As PackagePart = Nothing
Using pptPackage As Package = Package.Open(fileName, FileMode.Open, FileAccess.ReadWrite)
' Get the main document part (presentation.xml).
For Each relationship As PackageRelationship In pptPackage.GetRelationshipsByType(documentRelationshipType)
Dim documentUri As Uri = PackUriHelper.ResolvePartUri(New Uri("/", UriKind.Relative), relationship.TargetUri)
documentPart = pptPackage.GetPart(documentUri)
' There is only one document.
Exit For
Next
' Iterate through the slides and extract the title string from each.
Dim slidePart As PackagePart = Nothing
Dim slideUri As Uri = Nothing
Dim DocElement As OpenXmlElement = Nothing
'DocElement.SetAttributes(documentPart)
' Manage namespaces to perform Xml XPath queries.
Dim nt As New NameTable()
Dim nsManager As New XmlNamespaceManager(nt)
nsManager.AddNamespace(
"p", presentationmlNamespace)
nsManager.AddNamespace(
"a", drawingmlNamespace)
' Select each slide document part (slides/slideX.xml)
' via relationship with document part.
For Each relation As PackageRelationship In documentPart.GetRelationshipsByType(slideRelationshipType)
slideUri = PackUriHelper.ResolvePartUri(documentPart.Uri, relation.TargetUri)
slidePart = pptPackage.GetPart(slideUri)
' Get the slide part from the package.
Dim doc As XmlDocument = New XmlDocument(nt)
doc.Load(slidePart.GetStream())
'Insert the new slide and name it.
Dim newSlide As Slide =
newSlide.InnerText.Insert(0, title)
newSlide.InsertAt(DocElement, position)
' Locate the slide title using XPath.
' Note: This code assumes that the first text found is the title.
' Also note that if the title contains more than one font,
' or is in any way anything other than plain text, PowerPoint
' breaks it up into multiple elements. This code won't find a match
' in that case.
Dim xNode As XmlNode = doc.SelectSingleNode("//a:t", nsManager)
If xNode IsNot Nothing Then
' Perform a case-insensitive comparison.
'If String.Compare(xNode.InnerText, positionAfterTitle, True) = 0 Then
'Insert the new slide and name it.
Dim newSlide As Slide = xNode.
newSlide.InnerText.Insert(0, title)
newSlide.InsertAt(DocElement, position)
'End If
End If
Next
End Using
Return returnValue
End Function
Any help would be apreciated and would definately save the government in paper costs.
Thanks
James
James Cassidy