如何:向文檔添加頁首和頁尾

來源:互聯網
上載者:User

http://msdn.microsoft.com/zh-cn/library/ms178795.aspx

可以使用 Section 的Headers
屬性和Footers 屬性向文檔中的頁首和頁尾添加文本。文檔的每一部分都包含三個頁首和頁尾:

  • wdHeaderFooterPrimary

  • wdHeaderFooterEvenPages

  • wdHeaderFooterFirstPage

對於文件層級自訂項和應用程式層級增益集,這些過程有所不同。

適用於:本主題中的資訊適用於 Word 2007 和 Word 2010 的文檔級項目和應用程式級項目。有關更多資訊,請參見按 Office 應用程式和項目類型提供的功能。

文件層級自訂項

若要使用以下各程式碼範例,請從項目內的 ThisDocument 類運行這些樣本。

向文檔中的頁尾添加文本
  • 下面的程式碼範例設定要插入到文檔各部分首頁腳中的文本的字型,然後將文本插入到頁尾中。

    C#VB
    foreach (Word.Section wordSection in this.Sections){    Word.Range footerRange = wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;    footerRange.Font.ColorIndex = Word.WdColorIndex.wdDarkRed;    footerRange.Font.Size = 20;    footerRange.Text = "Confidential";}
向文檔中的頁首添加文本
  • 下面的程式碼範例添加一個欄位以在文檔中的每個頁首中顯示頁碼,然後設定段落對齊以使文本與頁首呈靠右對齊。

    C#VB
    foreach (Word.Section section in this.Sections){    Word.Range headerRange = section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;    headerRange.Fields.Add(headerRange, Word.WdFieldType.wdFieldPage);    headerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;}
應用程式層級增益集

若要使用以下各程式碼範例,請從項目內的 ThisAddIn 類運行這些樣本。

向文檔中的頁尾添加文本
  • 下面的程式碼範例設定要插入到文檔各部分首頁腳中的文本的字型,然後將文本插入到頁尾中。此程式碼範例使用使用中文件。

    C#VB
    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 = "Confidential";}
向文檔中的頁首添加文本
  • 下面的程式碼範例添加一個欄位以在文檔中的每個頁首中顯示頁碼,然後設定段落對齊以使文本與頁首呈靠右對齊。此程式碼範例使用使用中文件。

    C#VB
    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;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.