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

后端 未结 1 486
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-07 13:35

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 pa

相关标签:
1条回答
  • 2021-01-07 13:41

    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";
    
    0 讨论(0)
提交回复
热议问题