應用C#完成在word中拔出頁眉頁腳的辦法。本站提示廣大學習愛好者:(應用C#完成在word中拔出頁眉頁腳的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是應用C#完成在word中拔出頁眉頁腳的辦法正文
針對Word的操作是許多法式都具有的功效,本文即以實例展現應用C#完成在word中拔出頁眉頁腳的辦法,供年夜家參考自創,詳細辦法以下:
1、拔出頁腳的辦法:
public void InsertFooter(string footer) { if (ActiveWindow.ActivePane.View.Type == WdViewType.wdNormalView || ActiveWindow.ActivePane.View.Type == WdViewType.wdOutlineView) { ActiveWindow.ActivePane.View.Type = WdViewType.wdPrintView; } ActiveWindow.View.SeekView = WdSeekView.wdSeekCurrentPageFooter; this.Application.Selection.HeaderFooter.LinkToPrevious = false; this.Application.Selection.HeaderFooter.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; ActiveWindow.ActivePane.Selection.InsertAfter(footer); //跳出頁眉頁腳設置 ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; }
2、msdn上的辦法:
foreach (Word.Section wordSection in this.Application.ActiveDocument.Sections) { Word.Range footerRange = wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range; footerRange.Font.ColorIndex = Word.WdColorIndex.wdDarkRed; footerRange.Font.Size = 20; footerRange.Text = "頁腳 頁腳"; } foreach (Word.Section section in this.Application.ActiveDocument.Sections) { Word.Range headerRange = section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range; headerRange.Fields.Add(headerRange, Word.WdFieldType.wdFieldPage); headerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight; }
願望本文實例可以或許對年夜家的C#法式設計起到必定的贊助感化。