半岛权威十大直营(官方)网站

Word控件Spire.Doc 【页眉页脚】教程(7): 添加不同的半岛权威十大直营(官方)网站页眉和页脚

翻译|使用教程|编辑:胡涛|2023-03-29 10:24:45.280|阅读 67 次

概述: 本文将介绍如何添加不同的半岛权威十大直营(官方)网站页眉和页脚

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>

相关链接:

Spire.Doc for .NET是一款专门对 Word 文档进行操作的 .NET 类库。在于帮助开发人员无需安装 Microsoft Word情况下,轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。拥有近10年专业开发经验Spire系列办公文档开发工具,专注于创建、编辑、转换和打印Word/PDF/Excel等格式文件处理,小巧便捷。 

E-iceblue 功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理软件 WPS(如 .wps/.et/.dps 等格式

Spire.Doc for.NET 最新下载

在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");

影响

How to add different first page header & footer

How to add different first page header & footer

完整代码

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@wqylolg.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP