Word控件Spire.Doc 【段落处理】教程(四):如何在 C#、VB.NET 中设置 Word 项目符号样式

发布于:2023-01-13 ⋅ 阅读:(594) ⋅ 点赞:(0)

Word Bullet 可以将多个段落格式化为列表。它可以用项目符号强调段落并吸引读者的注意力。使用项目符号,列出的段落将自动缩进符号,可以是点、数字或其他自定义符号(如小星、三角形、箭头等)。

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

Spire.Doc for .NET是一个易于使用的组件,用于为开发人员的 .NET 应用程序操作 Word 文档,使用户可以为文档中的段落设置 Word 项目符号样式。本指南将重点介绍如何通过 Spire.Doc for .NET 使用 C#、VB.NET 实现此功能。

加载文档后,获取要设置项目符号样式的段落,然后调用 p.ListFormat.ApplyBulletStyle() 方法进行格式化。此外,您可以设置当前列表的 NumberPosition 属性以获取项目符号和段落内容之间的间距。下载并安装 Spire.Doc for .NET。然后使用以下代码设置 Word 项目符号样式。

[C#]

using Spire.Doc;
using Spire.Doc.Documents;

namespace WordBullets
{
class Program
{
static void Main(string[] args)
{
//Load Document
Document doc = new Document();
doc.LoadFromFile(@"E:\References.docx");

//Set Bullet Style
Section s = doc.Sections[0];

for (int i = 1; i< s.Paragraphs.Count; i++)
{
Paragraph p = s.Paragraphs[i];
p.ListFormat.ApplyBulletStyle();
p.ListFormat.CurrentListLevel.NumberPosition = -10;
}

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

[VB.NET]

Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace WordBullets
Friend Class Program
Shared Sub Main(ByVal args() As String)
'Load Document
Dim doc As New Document()
doc.LoadFromFile("E:\References.docx")

'Set Bullet Style
Dim s As Section = doc.Sections(0)

For i As Integer = 1 To s.Paragraphs.Count - 1
Dim p As Paragraph = s.Paragraphs(i)
p.ListFormat.ApplyBulletStyle()
p.ListFormat.CurrentListLevel.NumberPosition = -10
Next i

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

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


网站公告

今日签到

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