Word控件Spire.Doc 【页面背景】教程(6) ;如何设置页面边框的位置和自定义样式

注意:在开始之前,请下载最新版本的Spire.Doc,并在bin文件夹中添加.dll作为Visual Studio的参考。

第 1 步:加载没有页面边框的示例文档。

Document document = new Document();document.LoadFromFile("S.docx");Section section = document.Sections[0];

第 2 步:设置页面边框的位置及其间距。效果将显示从文本测量的页面边框和具有相同间距的页面边缘之间的差异。

section.PageSetup.PageBorderOffsetFrom = PageBorderOffsetFrom.PageEdge;section.PageSetup.Borders.Top.Space = 20;section.PageSetup.Borders.Bottom.Space = 30;section.PageSetup.Borders.Left.Space = 20;section.PageSetup.Borders.Right.Space =25;

第 3 步:设置页面上、下、左、右边框的样式和颜色,即自定义页面边框。

section.PageSetup.Borders.Top.BorderType = BorderStyle.Double;section.PageSetup.Borders.Bottom.BorderType = BorderStyle.Engrave3D;section.PageSetup.Borders.Left.BorderType = BorderStyle.Double;section.PageSetup.Borders.Right.BorderType = BorderStyle.Double;section.PageSetup.Borders.Top.Color = Color.YellowGreen;section.PageSetup.Borders.Bottom.Color = Color.DeepSkyBlue;section.PageSetup.Borders.Left.Color = Color.DeepSkyBlue;section.PageSetup.Borders.Right.Color = Color.DeepSkyBlue;

第 4 步:保存文档并启动以查看效果。

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();document.LoadFromFile("S.docx");Section section = document.Sections[0];section.PageSetup.PageBorderOffsetFrom = PageBorderOffsetFrom.PageEdge;section.PageSetup.Borders.Top.Space = 20;section.PageSetup.Borders.Bottom.Space = 30;section.PageSetup.Borders.Left.Space = 20;section.PageSetup.Borders.Right.Space =25;section.PageSetup.Borders.Top.BorderType = BorderStyle.Double;section.PageSetup.Borders.Bottom.BorderType = BorderStyle.Engrave3D;section.PageSetup.Borders.Left.BorderType = BorderStyle.Double;section.PageSetup.Borders.Right.BorderType = BorderStyle.Double;section.PageSetup.Borders.Top.Color = Color.YellowGreen;section.PageSetup.Borders.Bottom.Color = Color.DeepSkyBlue;section.PageSetup.Borders.Left.Color = Color.DeepSkyBlue;section.PageSetup.Borders.Right.Color = Color.DeepSkyBlue;document.SaveToFile("result.docx", FileFormat.Docx2013);System.Diagnostics.Process.Start("result.docx");}}}

欢迎下载|体验更多E-iceblue产品

获取更多信息请咨询在线客服  


标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年6月3日
下一篇 2022年6月4日

相关推荐

发表回复

登录后才能评论