本指南中的解决方案介绍了如何在 C# 和 VB.NET 中插入和格式化 Word 页面边框。
Word 页面边框是页面背景的一部分,用于美化文档外观。本指南中的解决方案介绍了如何在 C# 和 VB.NET 中插入和格式化 Word 页面边框。
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 DocumentDocument document = new Document();document.LoadFromFile(@"E:WorkDocumentsMicrosoft Word 2013 Preview.docx");Section section = document.Sections[0];//Add Page Borders with Special Style and Colorsection.PageSetup.Borders.BorderType = BorderStyle.DoubleWave;section.PageSetup.Borders.Color = Color.LightSeaGreen;//Space between Border and Textsection.PageSetup.Borders.Left.Space = 50;section.PageSetup.Borders.Right.Space = 50;//Save and Launchdocument.SaveToFile("PageBorders.docx", FileFormat.Docx);System.Diagnostics.Process.Start("PageBorders.docx");}}}
[VB.NET]
Imports System.DrawingImports Spire.DocImports Spire.Doc.DocumentsNamespace WordBorderFriend Class PageBordersShared Sub Main(ByVal args() As String)'Load DocumentDim document As New Document()document.LoadFromFile("E:WorkDocumentsMicrosoft Word 2013 Preview.docx")Dim section As Section = document.Sections(0)'Add Page Borders with Special Style and Colorsection.PageSetup.Borders.BorderType = BorderStyle.DoubleWavesection.PageSetup.Borders.Color = Color.LightSeaGreen'Space between Border and Textsection.PageSetup.Borders.Left.Space = 50section.PageSetup.Borders.Right.Space = 50'Save and Launchdocument.SaveToFile("PageBorders.docx", FileFormat.Docx)System.Diagnostics.Process.Start("PageBorders.docx")End SubEnd ClassEnd Namespace
欢迎下载|体验更多E-iceblue产品
获取更多信息请咨询在线客服 ;
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!