Jpa*_*aul 0 c# ms-office office-interop winforms
如何使用Microsoft.office.interop.word在文档中创建其他首页标题和页脚。
我尝试了以下代码,但仅在第一页中,页眉和页脚即将到来。我想用另一种方式(第一页不应有页眉和页脚)。谁能帮帮我吗 ?我尝试了很多。
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");
Run Code Online (Sandbox Code Playgroud)
尝试这个 -
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";
Run Code Online (Sandbox Code Playgroud)