使用C#實現在word中插入頁首頁尾的方法

來源:互聯網
上載者:User

標籤:print   wds   ade   插入   div   功能   count   使用   round   

針對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中插入頁首頁尾的方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.