Word控件Spire.Doc 【页面背景】教程(2) ;C在 C#、VB.NET 中为 Word 添加页面边框

发布于:2022-11-29 ⋅ 阅读:(473) ⋅ 点赞:(0)

Word 页面边框是页面背景的一部分,用于美化文档外观。本指南中的解决方案介绍了如何在 C# 和 VB.NET 中插入和格式化 Word 页面边框。

Spire.Doc for.NET 最新下载icon-default.png?t=M85Bhttps://www.evget.com/product/3368/download

MS Word 使用户能够装饰 Word 页面以获得更好的布局或外观。页面边框的所有格式都可以自定义,包括样式、颜色、宽度、边距等。本指南演示如何为 Word 文档添加页面边框,并通过Spire.Doc for .NET在 C# 和 VB.NET 中对其进行格式化。以下屏幕截图显示了编程后带有页面边框的 Word。

Spire.Doc for .NET 提供Section类,允许您创建新的部分实例或操作现有的部分。Borders是Section 类的PageSetup的属性之一。您可以直接设置Borders 的BorderType属性来添加页面边框并设置Color , Space of Left/Right属性来格式化边框。.NET 的 Spire.Doc 提供的边框类型包括 None、Single、Thick、Double、Hairline、Dot、DashLargeGap、DotDash、DotDotDash、Triple、ThinkThickSmallGap、ThinThinSampllGap、ThinThickThinSamllGap、ThickThickMediumGap、ThickThinMediumGap、ThickThickThinMediumGap、ThickThickLargeThickThick、ThickThinLargeGap、WaveGap、 , DoubleWave, DashSamllGap, DashDotStroker, Emboss3D, Engrave3D, Outset, Inset, TwistedLines1, 清除。在本例中,边框类型设置为 DoubleWave。

下载并安装 Spire.Doc for .NET并遵循以下代码:

[C#]

using System.Drawing;
using Spire.Doc;
using Spire.Doc.Documents;

namespace WordBorder
{
class PageBorders
{
static void Main(string[] args)
{
//Load Document
Document document = new Document();
document.LoadFromFile(@"E:\Work\Documents\Microsoft Word 2013 Preview.docx");
Section section = document.Sections[0];

//Add Page Borders with Special Style and Color
section.PageSetup.Borders.BorderType = BorderStyle.DoubleWave;
section.PageSetup.Borders.Color = Color.LightSeaGreen;
//Space between Border and Text
section.PageSetup.Borders.Left.Space = 50;
section.PageSetup.Borders.Right.Space = 50;

//Save and Launch
document.SaveToFile("PageBorders.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("PageBorders.docx");
}
}
}

[VB.NET]

Imports System.Drawing
Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace WordBorder
Friend Class PageBorders
Shared Sub Main(ByVal args() As String)
'Load Document
Dim document As New Document()
document.LoadFromFile("E:\Work\Documents\Microsoft Word 2013 Preview.docx")
Dim section As Section = document.Sections(0)

'Add Page Borders with Special Style and Color
section.PageSetup.Borders.BorderType = BorderStyle.DoubleWave
section.PageSetup.Borders.Color = Color.LightSeaGreen
'Space between Border and Text
section.PageSetup.Borders.Left.Space = 50
section.PageSetup.Borders.Right.Space = 50

'Save and Launch
document.SaveToFile("PageBorders.docx", FileFormat.Docx)
System.Diagnostics.Process.Start("PageBorders.docx")
End Sub
End Class
End Namespace

Spire.Doc 是一个独立的组件,使开发人员/程序员能够在WPF、.NET和Silverlight中生成、打开、编写、编辑和保存 Word 文档,而无需在系统上安装 Microsoft Word。

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到