Removing Header and Footer

VSTO Words

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");


Download

Last edited Feb 4, 2014 at 4:49 AM by asposemarketplace, version 2