Removing Header and Footer
Contents
[
Hide
]
VSTO
Word.Document doc = Application.Documents.Open("Add Headers and Footers.doc");
Globals.ThisAddIn.Application.ActiveDocument.Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Paragraphs.Last.Range.Delete();
Globals.ThisAddIn.Application.ActiveDocument.Sections[1].Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Paragraphs.Last.Range.Delete();
Aspose.Words
Document doc = new Document("Remove Headers and Footers.doc");
foreach (Section section in doc)
{
section.HeadersFooters.RemoveAt(0);
HeaderFooter footer;
// Primary footer is the footer used for odd pages.
footer = section.HeadersFooters[HeaderFooterType.FooterPrimary];
if (footer != null)
footer.Remove();
}
doc.Save("Remove Headers and Footers.doc");