翻譯|使用教程|編輯:胡濤|2023-03-29 10:24:45.280|閱讀 153 次
概述: 本文將介紹如何添加不同的金喜正規買球頁眉和頁腳
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發人員無需安裝 Microsoft Word情況下,輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業開發經驗Spire系列辦公文檔開發工具,專注于創建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團隊研發,不依賴第三方軟件,不受其他國家的技術或法律法規限制,同時適配國產操作系統如中科方德、中標麒麟等,兼容國產文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
在MS Word頁眉&頁腳工具選項中,我們可以選擇“不同的金喜正規買球”和“不同的奇數和偶數頁”。文章“如何為奇數和偶數頁創建不同的頁眉/頁腳”介紹了使用Spire.Doc設置不同奇數和偶數頁的方法。Spire.DOC還提供了一個簡單快捷的方法來添加不同的金喜正規買球頁眉&頁腳。本文將介紹添加不同金喜正規買球頁眉頁腳的方法&。
僅供參考,如果您只需要第一頁的頁眉和頁腳,請只設置第一頁的頁眉&頁腳,其余的就不用管了。通過這種方式,您的Word文檔將只有頁眉&頁腳在第一頁,這提供了一個更簡單的方法來添加一個頁眉只到第一頁的文件比文章中提到的方法“如何添加一個頁眉只到第一頁的文件“。
注意 :在開始之前,請下載Spire.Doc的最新版本,并在bin文件夾中添加Spire.Doc .dll作為Visual Studio的引用。
步驟1:加載僅包含文本的示例文檔。
Document document = new Document(); document.LoadFromFile("T.docx");
步驟2:獲取節并設置屬性true。
Section section = document.Sections[0]; section.PageSetup.DifferentFirstPageHeaderFooter = true;
步驟3:設置第一個頁眉。這里我們附加一張圖片作為標題。
Paragraph paragraph1 = section.HeadersFooters.FirstPageHeader.AddParagraph(); paragraph1.Format.HorizontalAlignment = HorizontalAlignment.Right; DocPicture headerimage = paragraph1.AppendPicture(Image.FromFile("2.bmp"));
步驟4:設置第一個頁腳。
paragraph2.Format.HorizontalAlignment = HorizontalAlignment.Center;
步驟5:設置其他頁眉&頁腳。如果你只需要第一頁的頁眉&頁腳,不要設置這個。
Paragraph paragraph2 = section.HeadersFooters.FirstPageFooter.AddParagraph(); paragraph2.Format.HorizontalAlignment = HorizontalAlignment.Center; TextRange FF = paragraph2.AppendText("First Page Footer"); FF.CharacterFormat.FontSize = 20;
第6步:保存文檔并啟動以查看效果。
document.SaveToFile("R.docx", FileFormat.Docx2010); System.Diagnostics.Process.Start("R.docx");
影響 :
完整代碼:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; using System.Drawing; namespace Mirror_Margin { class Program { static void Main(string[] args) { Document document = new Document(); document.LoadFromFile("T.docx"); Section section = document.Sections[0]; section.PageSetup.DifferentFirstPageHeaderFooter = true; Paragraph paragraph1 = section.HeadersFooters.FirstPageHeader.AddParagraph(); paragraph1.Format.HorizontalAlignment = HorizontalAlignment.Right; DocPicture headerimage = paragraph1.AppendPicture(Image.FromFile("2.bmp")); Paragraph paragraph2 = section.HeadersFooters.FirstPageFooter.AddParagraph(); paragraph2.Format.HorizontalAlignment = HorizontalAlignment.Center; TextRange FF = paragraph2.AppendText("First Page Footer"); FF.CharacterFormat.FontSize = 20; Paragraph paragraph3 = section.HeadersFooters.Header.AddParagraph(); paragraph3.Format.HorizontalAlignment = HorizontalAlignment.Center; TextRange NH = paragraph3.AppendText("If you only need first page header, don't set this."); NH.CharacterFormat.FontSize = 20; Paragraph paragraph4 = section.HeadersFooters.Footer.AddParagraph(); paragraph4.Format.HorizontalAlignment = HorizontalAlignment.Center; TextRange NF = paragraph4.AppendText("If you only need first page footer, don't set this."); NF.CharacterFormat.FontSize = 20; document.SaveToFile("R.docx", FileFormat.Docx2010); System.Diagnostics.Process.Start("R.docx"); } } }
以上便如何添加不同的金喜正規買球頁眉和頁腳,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群。
歡迎下載|體驗更多E-iceblue產品
獲取更多信息請咨詢 ;技術交流Q群(767755948)
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn