翻譯|使用教程|編輯:胡濤|2023-03-29 10:24:45.280|閱讀 164 次
概述: 本文將介紹如何添加不同的半島外圍網(wǎng)上直營頁眉和頁腳
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Spire.Doc for .NET是一款專門對 Word 文檔進(jìn)行操作的 .NET 類庫。在于幫助開發(fā)人員無需安裝 Microsoft Word情況下,輕松快捷高效地創(chuàng)建、編輯、轉(zhuǎn)換和打印 Microsoft Word 文檔。擁有近10年專業(yè)開發(fā)經(jīng)驗Spire系列辦公文檔開發(fā)工具,專注于創(chuàng)建、編輯、轉(zhuǎn)換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團(tuán)隊研發(fā),不依賴第三方軟件,不受其他國家的技術(shù)或法律法規(guī)限制,同時適配國產(chǎn)操作系統(tǒng)如中科方德、中標(biāo)麒麟等,兼容國產(chǎn)文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
在MS Word頁眉&頁腳工具選項中,我們可以選擇“不同的半島外圍網(wǎng)上直營”和“不同的奇數(shù)和偶數(shù)頁”。文章“如何為奇數(shù)和偶數(shù)頁創(chuàng)建不同的頁眉/頁腳”介紹了使用Spire.Doc設(shè)置不同奇數(shù)和偶數(shù)頁的方法。Spire.DOC還提供了一個簡單快捷的方法來添加不同的半島外圍網(wǎng)上直營頁眉&頁腳。本文將介紹添加不同半島外圍網(wǎng)上直營頁眉頁腳的方法&。
僅供參考,如果您只需要第一頁的頁眉和頁腳,請只設(shè)置第一頁的頁眉&頁腳,其余的就不用管了。通過這種方式,您的Word文檔將只有頁眉&頁腳在第一頁,這提供了一個更簡單的方法來添加一個頁眉只到第一頁的文件比文章中提到的方法“如何添加一個頁眉只到第一頁的文件“。
注意 :在開始之前,請下載Spire.Doc的最新版本,并在bin文件夾中添加Spire.Doc .dll作為Visual Studio的引用。
步驟1:加載僅包含文本的示例文檔。
Document document = new Document();
document.LoadFromFile("T.docx");
步驟2:獲取節(jié)并設(shè)置屬性true。
Section section = document.Sections[0]; section.PageSetup.DifferentFirstPageHeaderFooter = true;
步驟3:設(shè)置第一個頁眉。這里我們附加一張圖片作為標(biāo)題。
Paragraph paragraph1 = section.HeadersFooters.FirstPageHeader.AddParagraph();
paragraph1.Format.HorizontalAlignment = HorizontalAlignment.Right;
DocPicture headerimage = paragraph1.AppendPicture(Image.FromFile("2.bmp"));
步驟4:設(shè)置第一個頁腳。
paragraph2.Format.HorizontalAlignment = HorizontalAlignment.Center;
步驟5:設(shè)置其他頁眉&頁腳。如果你只需要第一頁的頁眉&頁腳,不要設(shè)置這個。
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");
}
}
}
以上便如何添加不同的半島外圍網(wǎng)上直營頁眉和頁腳,如果您有其他問題也可以繼續(xù)瀏覽本系列文章,獲取相關(guān)教程,你還可以給我留言或者加入我們的官方技術(shù)交流群。
歡迎下載|體驗更多E-iceblue產(chǎn)品
獲取更多信息請咨詢 ;技術(shù)交流Q群(767755948)
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@ke049m.cn