1. 程式人生 > >使用C#實現在word中插入頁眉頁腳的方法

使用C#實現在word中插入頁眉頁腳的方法

spa dex arp false datatable fault prev lec 幫助

針對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#實現在word中插入頁眉頁腳的方法

本文地址: http://www.paobuke.com/develop/c-develop/pbk23632.html






相關內容

技術分享C#七大經典排序算法系列(上)技術分享C#給PDF文件添加水印技術分享C#實現文件上傳與下載功能實例技術分享C# DataTable中Compute方法用法集錦(數值/字符串/運算符/表等操作)
技術分享C#編程自學之數據類型和變量一技術分享C#發送數據到剪貼板及從剪貼板中取數據的方法技術分享C#自定義序列化ISerializable的實現方法技術分享
C#中is與as的區別分析

使用C#實現在word中插入頁眉頁腳的方法