半岛权威十大直营(官方)网站

Word控件Spire.Doc 【页面背景】教程(3) ;如何在 C# 中设置单词段落底纹

翻译|使用教程|编辑:胡涛|2022-07-01 14:07:11.917|阅读 88 次

概述:本指南中的解决方案介绍了如何在 C# 和 VB.NET 中插入和格式化 Word 页面边框。

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>

相关链接:

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

Spire.Doc for.NET 最新下载

通过对word文档中的单词或段落进行阴影处理,我们可以强调信息并轻松吸引他人的注意力。本文将向您展示如何在的帮助下在 C# 中设置段落底纹。

首先,下载 Spire.Doc并安装在您的系统上。Spire.Doc 安装干净、专业,并包含在 MSI 安装程序中。

然后,通过以下路径在下载的 Bin 文件夹中添加 Spire.Doc.dll 作为参考:“..\Spire.Doc\Bin\NET4.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 paragraph
paragaph.Format.BackColor = Color.Yellow;

//Set background color for the selected text of paragraph
paragaph = 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 paragraph
paragaph.Format.BackColor = Color.Yellow;

//Set background color for the selected text of paragraph
paragaph = 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产品

获取更多信息请咨询  ;技术交流Q群(767755948)


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@wqylolg.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
相关产品
Spire.Doc for .NET

Spire.Doc for .NET 是一款专门对 Word 文档进行操作的 .NET 类库。

Spire.XLS for .NET

Spire.XLS for .NET是专业.NET Excel组件,快速完成对Excel各类编程操作

Spire.Office for .NET

专业的.NET Office套件,涵盖office文档创建、编辑、转换、管理和OCR内容识别等操作

Aspose.Cells for .NET

专业的电子表格控件,无需MS Excel也可满足一切Excel表格功能。

Aspose.Words for .NET

无需Microsoft Word也可在任何平台上满足Word文档的一切操作需求。

title
title
title
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP