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

不羁岁月 提交于 2019-11-30 21:10:38

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/15655387/different-first-page-in-a-document-using-microsoft-office-interop-word-in-c-shar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!