本指南中的解决方案介绍了如何在 C# 和 VB.NET 中插入和格式化 Word 页面边框。
Word 页面边框是页面背景的一部分,用于美化文档外观。本指南中的解决方案介绍了如何在 C# 和 VB.NET 中插入和格式化 Word 页面边框。
首先,下载 Spire.Doc并安装在您的系统上。Spire.Doc 安装干净、专业,并包含在 MSI 安装程序中。
然后,通过以下路径在下载的 Bin 文件夹中添加 Spire.Doc.dll 作为参考:“..Spire.DocBinNET4.0 Spire.Doc.dll”。
现在介绍如何设置文本或段落的背景颜色的步骤。
第 1 步:创建一个新的 word 文档并从文件中加载。
[C#]
Document document = new Document();document.LoadFromFile(@"....Sample.docx");
第 2 步:获取一个段落。
[C#]
Paragraph paragaph = document.Sections[0].Paragraphs[0];
第 3 步:为段落或选定的单词添加阴影。
[C#]
//Set background color for the paragraphparagaph.Format.BackColor = Color.Yellow;//Set background color for the selected text of paragraphparagaph = document.Sections[0].Paragraphs[1];TextSelection selection= paragaph.Find("Blues",true,false);TextRange range = selection.GetAsOneRange();range.CharacterFormat.TextBackgroundColor = Color.Yellow;Paragraph paragaph = document.Sections[0].Paragraphs[0];
第 4 步:将文档保存到文件中。
[C#]
document.SaveToFile("sample.docx",FileFormat.Docx);
效果截图:

完整代码:
[C#]
using Spire.Doc;using Spire.Doc.Documents;using Spire.Doc.Fields;namespace SetWordParagh{class Program{static void Main(string[] args){Document document = new Document();document.LoadFromFile(@"....Sample.docx");Paragraph paragaph = document.Sections[0].Paragraphs[0];//Set background color for the paragraphparagaph.Format.BackColor = Color.Yellow;//Set background color for the selected text of paragraphparagaph = document.Sections[0].Paragraphs[1];TextSelection selection= paragaph.Find("Blues",true,false);TextRange range = selection.GetAsOneRange();range.CharacterFormat.TextBackgroundColor = Color.Yellow;document.SaveToFile("sample.docx",FileFormat.Docx);}}}
欢迎下载|体验更多E-iceblue产品
获取更多信息请咨询在线客服 ;
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!