We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How do I insert headers and footers in a document?

 

Section.HeadersFooters property is used to set the document headers and footers. We can insert document elements like images and tables inside the header and footer. Here is a code snippet that demonstrates the usage.

C#

 // Creating a new document.

WordDocument doc = new WordDocument();

// Add a new section to the document.

IWSection section = doc.AddSection();

// Add a new paragraph for header to the document.

 IWParagraph headerPar = new WParagraph(doc);

 // Add the paragraph to the header section.

section.HeadersFooters.Header.Paragraphs.Add(headerPar);

// Add a new paragraph for header to the document.

IWParagraph footerPar = new WParagraph(doc);

 // Add the paragraph to the Footer section. section.HeadersFooters.Footer.Paragraphs.Add(footerPar)

 

VB

 '' Creating a new document.

Dim doc As WordDocument = New WordDocument()

'' Add a new section to the document.

Dim section As IWSection = doc.AddSection()

'' Add a new paragraph for header to the document.

Dim headerPar As IWParagraph = New WParagraph(doc)

'' Add the paragraph to the header section.

CType(section.HeadersFooters.Header.Paragraphs, WParagraphCollection).Add(headerPar)

'' Add the paragraph to the Footer section.

CType(section.HeadersFooters.Footer.Paragraphs, WParagraphCollection).Add(footerPar)

 

Here is the sample.

Header And Footer.zip

Article ID: Published Date: Last Revised Date: Platform: Control:
275 04/30/2011 07/10/2014 Windows Forms DocIO
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.