翻譯|使用教程|編輯:胡濤|2023-03-31 10:26:47.143|閱讀 200 次
概述:本文將介紹設(shè)置頁面邊框是否包圍頁眉/頁腳的方法。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Spire.Doc for .NET是一款專門對(duì) Word 文檔進(jìn)行操作的 .NET 類庫。在于幫助開發(fā)人員無需安裝 Microsoft Word情況下,輕松快捷高效地創(chuàng)建、編輯、轉(zhuǎn)換和打印 Microsoft Word 文檔。擁有近10年專業(yè)開發(fā)經(jīng)驗(yàn)Spire系列辦公文檔開發(fā)工具,專注于創(chuàng)建、編輯、轉(zhuǎn)換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團(tuán)隊(duì)研發(fā),不依賴第三方軟件,不受其他國家的技術(shù)或法律法規(guī)限制,同時(shí)適配國產(chǎn)操作系統(tǒng)如中科方德、中標(biāo)麒麟等,兼容國產(chǎn)文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
在 MS Word 頁面邊框選項(xiàng)中,有復(fù)選框可以選擇頁面邊框是否包圍頁眉/頁腳。此功能非常重要,可用于管理頁面邊框和頁眉/頁腳之間的位置關(guān)系。Spire.Doc 支持設(shè)置兩個(gè)常用功能:頁面邊框和頁眉/頁腳,也支持管理它們的空間關(guān)系。本文將介紹設(shè)置頁面邊框是否包圍頁眉/頁腳的方法。
注意:開始之前,請(qǐng)下載最新版本的Spire.Doc,并在bin文件夾中添加.dll作為Visual Studio的引用。
第 1 步:創(chuàng)建一個(gè) Word 文檔并添加一個(gè)部分。
Document document = new Document(); Section section = document.AddSection();
第 2 步:使用 Spire.Doc 庫向文檔添加示例頁面邊框。
section.PageSetup.Borders.BorderType = BorderStyle.Wave; section.PageSetup.Borders.Color = Color.Green; section.PageSetup.Borders.Left.Space = 20; section.PageSetup.Borders.Right.Space = 20;
第 3 步:使用 Spire.Doc 庫將樣本頁眉和頁腳添加到文檔中。
//add a header and set its format
Paragraph paragraph1 = section.HeadersFooters.Header.AddParagraph();
paragraph1.Format.HorizontalAlignment = HorizontalAlignment.Right;
TextRange headerText = paragraph1.AppendText("Header isn't included in page border");
headerText.CharacterFormat.FontName = "Calibri";
headerText.CharacterFormat.FontSize = 20;
headerText.CharacterFormat.Bold = true;
//add a footer and set its format
Paragraph paragraph2 = section.HeadersFooters.Footer.AddParagraph();
paragraph2.Format.HorizontalAlignment = HorizontalAlignment.Left;
TextRange footerText = paragraph2.AppendText("Footer is included in page border");
footerText.CharacterFormat.FontName = "Calibri";
footerText.CharacterFormat.FontSize = 20;
footerText.CharacterFormat.Bold = true;
第 4 步:設(shè)置頁眉不包含在頁面邊框中,頁腳包含在內(nèi)。
section.PageSetup.PageBorderIncludeHeader = false; section.PageSetup.HeaderDistance = 40; section.PageSetup.PageBorderIncludeFooter = true; section.PageSetup.FooterDistance = 40;
第 5 步:保存文檔并啟動(dòng)以查看效果。
System.Diagnostics.Process.Start("result.docx");
效果:
document.SaveToFile("result.docx", FileFormat.Docx2013);
System.Diagnostics.Process.Start("result.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();
Section section = document.AddSection();
section.PageSetup.Borders.BorderType = BorderStyle.Wave;
section.PageSetup.Borders.Color = Color.Green;
section.PageSetup.Borders.Left.Space = 20;
section.PageSetup.Borders.Right.Space = 20;
Paragraph paragraph1 = section.HeadersFooters.Header.AddParagraph();
paragraph1.Format.HorizontalAlignment = HorizontalAlignment.Right;
TextRange headerText = paragraph1.AppendText("Header isn't included in page border");
headerText.CharacterFormat.FontName = "Calibri";
headerText.CharacterFormat.FontSize = 20;
headerText.CharacterFormat.Bold = true;
Paragraph paragraph2 = section.HeadersFooters.Footer.AddParagraph();
paragraph2.Format.HorizontalAlignment = HorizontalAlignment.Left;
TextRange footerText = paragraph2.AppendText("Footer is included in page border");
footerText.CharacterFormat.FontName = "Calibri";
footerText.CharacterFormat.FontSize = 20;
footerText.CharacterFormat.Bold = true;
section.PageSetup.PageBorderIncludeHeader = false;
section.PageSetup.HeaderDistance = 40;
section.PageSetup.PageBorderIncludeFooter = true;
section.PageSetup.FooterDistance = 40;
document.SaveToFile("result.docx", FileFormat.Docx2013);
System.Diagnostics.Process.Start("result.docx");
}
}
}
以上便如何設(shè)置頁面邊框是否包圍頁眉/頁腳,如果您有其他問題也可以繼續(xù)瀏覽本系列文章,獲取相關(guān)教程,你還可以給我留言或者加入我們的官方技術(shù)交流群。
歡迎下載|體驗(yàn)更多E-iceblue產(chǎn)品
獲取更多信息請(qǐng)咨詢 ;技術(shù)交流Q群(767755948)
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@ke049m.cn