Jpaul
Jpaul

Reputation: 278

Different First Page in a document using microsoft office interop word in c#

How can i create a different first page header and footer in a document using Microsoft.office.interop.word.

I have tried the following code but only in the first page, header and footer is coming. I want it in the other way(first page shouldn't have header and footer). can any one Please help me ? i tried a lot.

 Microsoft.Office.Interop.Word.Application w = new icrosoft.Office.Interop.Word.Application();
 Microsoft.Office.Interop.Word.Document doc;
 w.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = -1;
 doc.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekCurrentPageHeader;
 doc.ActiveWindow.Selection.TypeText("HEader Text");   

Upvotes: 0

Views: 5609

Answers (1)

Arun
Arun

Reputation: 978

Try this -

 Microsoft.Office.Interop.Word.Application w = new icrosoft.Office.Interop.Word.Application();
 Microsoft.Office.Interop.Word.Document doc;
 doc = w.ActiveDocument;
 doc.PageSetup.DifferentFirstPageHeaderFooter = -1;

 // Setting Different First page Header & Footer
 doc.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterFirstPage].Range.Text = "First Page Header";
 doc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterFirstPage].Range.Text = "First Page Footer";

 // Setting Other page Header & Footer
 doc.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text = "Other Page Header";
 doc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text = "Other Page Footer";

Upvotes: 6

Related Questions