附加 HTML 代碼來設置 word 項目符號樣式
Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發(fā)人員無需安裝 Microsoft Word情況下,輕松快捷高效地創(chuàng)建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業(yè)開發(fā)經(jīng)驗Spire系列辦公文檔開發(fā)工具,專注于創(chuàng)建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團隊研發(fā),不依賴第三方軟件,不受其他國家的技術或法律法規(guī)限制,同時適配國產(chǎn)操作系統(tǒng)如中科方德、中標麒麟等,兼容國產(chǎn)文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
在 Spire.Doc for .NET 的幫助下,開發(fā)人員可以通過調(diào)用 p.ListFormat.ApplyBulletStyle() 方法輕松為現(xiàn)有 Word 文檔設置項目符號樣式進行格式化。本文將向您展示如何將 HTML 列表轉換為單詞并在 C# 中為單詞列表設置項目符號樣式。
首先,請查看結果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 步:設置段落的項目符號樣式。
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); } } }
以上便是如何通過在 C# 中附加 HTML 代碼來設置 word 項目符號樣式的教程,如果您有其他問題也可以繼續(xù)瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群。
歡迎下載|體驗更多E-iceblue產(chǎn)品
獲取更多信息請咨詢 ;技術交流Q群(767755948)