Word控件Spire.Doc 【段落处理】教程(七):如如何通过在 C# 中附加 HTML 代码来设置 word 项目符 样式

首先,请查看结果word文档的有效截图:

如何通过在 C# 中附加 HTML 代码来设置 word 项目符 样式

步骤如下:

第 1 步创建一个新文档并在文档中添加一个部分。

Document document = new Document();Section section=document.AddSection();

第 2 步通过附加 HTML 将单词列表添加到段落中。

Paragraph paragraph = section.AddParagraph();paragraph.AppendHTML("<ol><li>Version 1</li><li>Version 2</li><li>Version 3</li></ol>");

第 3 步设置段落的项目符 样式。

foreach (Paragraph p in section.Paragraphs){p.ApplyStyle(BuiltinStyle.Heading2);p.ListFormat.CurrentListLevel.NumberPosition = 20;p.ListFormat.CurrentListLevel.TextPosition = 30;}

第 4 步将文档保存到文件

document.SaveToFile("result.docx",FileFormat.Docx);

完整代码

using Spire.Doc;using Spire.Doc.Documents;namespace SetWordBullet{class Program{static void Main(string[] args){Document document = new Document();Section section = document.AddSection();Paragraph paragraph = section.AddParagraph();paragraph.AppendHTML("<ol><li>Version 1</li><li>Version 2</li><li>Version 3</li></ol>");foreach (Paragraph p in section.Paragraphs){p.ApplyStyle(BuiltinStyle.Heading2);p.ListFormat.CurrentListLevel.NumberPosition = 20;p.ListFormat.CurrentListLevel.TextPosition = 30;}document.SaveToFile("result.docx", FileFormat.Docx);}}}

欢迎下载|体验更多E-iceblue产品

如需获取更多产品相关信息请咨询在线客服  


标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年4月9日
下一篇 2022年4月9日

相关推荐

发表回复

登录后才能评论