Dependencies:
DocumentFormat.OpenXml.dll (version 2.0.3930.0)
Imports:
DocumentFormat.OpenXml.WordProcessing
DocumentFormat.OpenXml.Packaging
Code Snippet
- Private Sub DeleteHeaderAndFooterParts(ByRef myDoc As WordprocessingDocument)
- Dim headRefs As List(Of HeaderReference) = myDoc.MainDocumentPart.Document.Descendants(Of HeaderReference)().ToList()
- For Each headRef As HeaderReference In headRefs
- Dim relId As String = headRef.GetAttribute("id", wns_r).Value
- myDoc.MainDocumentPart.DeletePart(relId)
- headRef.Remove()
- Next
- Dim footRefs As List(Of FooterReference) = myDoc.MainDocumentPart.Document.Descendants(Of FooterReference)().ToList()
- For Each footRef As FooterReference In footRefs
- Dim relId As String = footRef.GetAttribute("id", wns_r).Value
- myDoc.MainDocumentPart.DeletePart(relId)
- footRef.Remove()
- Next
- myDoc.MainDocumentPart.Document.Save(myDoc.MainDocumentPart.GetStream(FileMode.Create))
- End Sub
No comments:
Post a Comment