文档半岛外围网上直营>>E-iceblue中文文档>>设置页面边框的位置和自定义样式
设置页面边框的位置和自定义样式
MS 页面边框选项提供了通过从文本或页面边缘测量的边距设置页面边框位置的选项。此外,它还提供了自定义页面边框的选项,通过设置上、下、左、右边框的样式和颜色。我们已经介绍了设置页面边框的方法,并使用Spire.Doc设置页面边框是否围绕页眉/页脚。本文将介绍Spire.Doc提供的在C#中设置页面边框的位置和自定义样式的解决方案。
注意:在开始之前,请下载最新版本的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");
}
}
}

QQ交谈
在线咨询

渝公网安备
50010702500608号

客服热线