翻譯|使用教程|編輯:胡濤|2022-05-12 16:43:11.800|閱讀 386 次
概述:本文將向您展示如何將 HTML 列表轉(zhuǎn)換為單詞并在 C# 中為單詞列表設(shè)置項(xiàng)目符號樣式。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
在 Spire.Doc for .NET 的幫助下,開發(fā)人員可以通過調(diào)用 p.ListFormat.ApplyBulletStyle() 方法輕松為現(xiàn)有 Word 文檔設(shè)置項(xiàng)目符號樣式進(jìn)行格式化。本文將向您展示如何將 HTML 列表轉(zhuǎn)換為單詞并在 C# 中為單詞列表設(shè)置項(xiàng)目符號樣式。
首先,請查看結(jié)果word文檔的有效截圖:
步驟如下:
第 1 步:創(chuàng)建一個新文檔并在文檔中添加一個部分。
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 步:設(shè)置段落的項(xiàng)目符號樣式。
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); } } }
歡迎下載|體驗(yàn)更多E-iceblue產(chǎn)品
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn