使用C#實現在word中插入頁眉頁腳的方法
更新時間:2014年08月20日 10:40:32 投稿:shichen2014
這篇文章主要介紹了使用C#實現在word中插入頁眉頁腳的方法,是操作Word的常見方法,有一定的學習借鑒價值,需要的朋友可以參考下
針對Word的操作是很多程序都具備的功能,本文即以實例展示使用C#實現在word中插入頁眉頁腳的方法,供大家參考借鑒,具體方法如下:
一、插入頁腳的方法:
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;
}
二、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#程序設計起到一定的幫助作用。
相關文章
C# listview添加combobox到單元格的實現代碼
從別處轉來的,自己進行了一些小的修改,還不錯,你自己先拖一個ListView1和一個ComboBox1,需要的朋友可以參考下2014-06-06
Winform圓形環(huán)繞的Loading動畫實現代碼
這篇文章主要介紹了Winform圓形環(huán)繞的Loading動畫實現代碼,有需要的朋友可以參考一下2014-01-01

