創(chuàng)建多級列表編號
Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發(fā)人員無需安裝 Microsoft Word情況下,輕松快捷高效地創(chuàng)建、編輯、轉(zhuǎn)換和打印 Microsoft Word 文檔。擁有近10年專業(yè)開發(fā)經(jīng)驗Spire系列辦公文檔開發(fā)工具,專注于創(chuàng)建、編輯、轉(zhuǎn)換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團隊研發(fā),不依賴第三方軟件,不受其他國家的技術(shù)或法律法規(guī)限制,同時適配國產(chǎn)操作系統(tǒng)如中科方德、中標麒麟等,兼容國產(chǎn)文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
多級列表編號允許您使用嵌套編號格式化和組織文本。多級列表最常見的形式是標題編號,它用大綱列表概括整篇文章,經(jīng)常出現(xiàn)在技術(shù)、學(xué)術(shù)和商業(yè)文檔中。在本文中,您將學(xué)習(xí)如何在 C#、VB.NET 中使用 Spire.Doc 生成多級列表編號。
詳細步驟:
第 1 步 : 創(chuàng)建一個新的 Word 文檔,添加一個部分。
Document document = new Document(); Section section = document.AddSection();
第 2 步:定義新的多級列表樣式。設(shè)置其名稱為levelstyle,設(shè)置ListType 為Numbered,設(shè)置level屬性的參數(shù)。此列表級別獨立于樣式運行并控制數(shù)字格式。
ListStyle listStyle = new ListStyle(document, ListType.Numbered); listStyle.Name = "levelstyle"; listStyle.Levels[0].PatternType = ListPatternType.Arabic; listStyle.Levels[1].NumberPrefix = "\x0000."; listStyle.Levels[1].PatternType = ListPatternType.Arabic; listStyle.Levels[2].NumberPrefix = "\x0000.\x0001."; listStyle.Levels[2].PatternType = ListPatternType.Arabic; document.ListStyles.Add(listStyle);
第 3 步:創(chuàng)建一個段落,將文本附加到段落并使用 Heading1 應(yīng)用段落樣式。將定義的列表樣式“l(fā)evelstyle”應(yīng)用于此段落。
Paragraph paragraph = section.AddParagraph(); paragraph.AppendText("The first item"); paragraph.ApplyStyle(BuiltinStyle.Heading1); paragraph.ListFormat.ApplyStyle("levelstyle");
第 4 步:重復(fù)第 3 步以向該文檔添加更多段落。在這里,您需要將不同的 ListLevelNumber 設(shè)置為 1 或 2,以確保將子段落和子段落分配給不同的列表模板。
paragraph = section.AddParagraph(); paragraph.AppendText("The second item"); paragraph.ApplyStyle(BuiltinStyle.Heading1); paragraph.ListFormat.ApplyStyle("levelstyle"); paragraph = section.AddParagraph(); paragraph.AppendText("The first sub-item"); paragraph.ApplyStyle(BuiltinStyle.Heading2); paragraph.ListFormat.ListLevelNumber = 1; paragraph.ListFormat.ApplyStyle("levelstyle"); paragraph = section.AddParagraph(); paragraph.AppendText("The second sub-item"); paragraph.ApplyStyle(BuiltinStyle.Heading2); paragraph.ListFormat.ContinueListNumbering(); paragraph.ListFormat.ApplyStyle("levelstyle"); paragraph = section.AddParagraph(); paragraph.AppendText("A sub-sub-item"); paragraph.ApplyStyle(BuiltinStyle.Heading5); paragraph.ListFormat.ListLevelNumber = 2; paragraph.ListFormat.ApplyStyle("levelstyle"); paragraph = section.AddParagraph(); paragraph.AppendText("The third item"); paragraph.ApplyStyle(BuiltinStyle.Heading1); paragraph.ListFormat.ApplyStyle("levelstyle");
第 5 步:保存文件。
公文。SaveToFile(@“result.docx”, FileFormat.Docx);
結(jié)果:
完整代碼:
[C#]
using Spire.Doc; using Spire.Doc.Documents; namespace CreatList { class Program { static void Main(string[] args) { Document document = new Document(); Section section = document.AddSection(); ListStyle listStyle = new ListStyle(document, ListType.Numbered); listStyle.Name = "levelstyle"; listStyle.Levels[0].PatternType = ListPatternType.Arabic; listStyle.Levels[1].NumberPrefix = "\x0000."; listStyle.Levels[1].PatternType = ListPatternType.Arabic; listStyle.Levels[2].NumberPrefix = "\x0000.\x0001."; listStyle.Levels[2].PatternType = ListPatternType.Arabic; document.ListStyles.Add(listStyle); Paragraph paragraph = section.AddParagraph(); paragraph.AppendText("The first item"); paragraph.ApplyStyle(BuiltinStyle.Heading1); paragraph.ListFormat.ApplyStyle("levelstyle"); paragraph = section.AddParagraph(); paragraph.AppendText("The second item"); paragraph.ApplyStyle(BuiltinStyle.Heading1); paragraph.ListFormat.ApplyStyle("levelstyle"); paragraph = section.AddParagraph(); paragraph.AppendText("The first sub-item"); paragraph.ApplyStyle(BuiltinStyle.Heading2); paragraph.ListFormat.ListLevelNumber = 1; paragraph.ListFormat.ApplyStyle("levelstyle"); paragraph = section.AddParagraph(); paragraph.AppendText("The second sub-item"); paragraph.ApplyStyle(BuiltinStyle.Heading2); paragraph.ListFormat.ContinueListNumbering(); paragraph.ListFormat.ApplyStyle("levelstyle"); paragraph = section.AddParagraph(); paragraph.AppendText("A sub-sub-item"); paragraph.ApplyStyle(BuiltinStyle.Heading5); paragraph.ListFormat.ListLevelNumber = 2; paragraph.ListFormat.ApplyStyle("levelstyle"); paragraph = section.AddParagraph(); paragraph.AppendText("The third item"); paragraph.ApplyStyle(BuiltinStyle.Heading1); paragraph.ListFormat.ApplyStyle("levelstyle"); document.SaveToFile(@"result.docx", FileFormat.Docx); } } }
[VB.NET]
Imports Spire.Doc Imports Spire.Doc.Documents Namespace CreatList Class Program Private Shared Sub Main(args As String()) Dim document As New Document() Dim section As Section = document.AddSection() Dim listStyle As New ListStyle(document, ListType.Numbered) listStyle.Name = "levelstyle" listStyle.Levels(0).PatternType = ListPatternType.Arabic listStyle.Levels(1).NumberPrefix = vbNullChar & "." listStyle.Levels(1).PatternType = ListPatternType.Arabic listStyle.Levels(2).NumberPrefix = vbNullChar & "." & ChrW(1) & "." listStyle.Levels(2).PatternType = ListPatternType.Arabic document.ListStyles.Add(listStyle) Dim paragraph As Paragraph = section.AddParagraph() paragraph.AppendText("The first item") paragraph.ApplyStyle(BuiltinStyle.Heading1) paragraph.ListFormat.ApplyStyle("levelstyle") paragraph = section.AddParagraph() paragraph.AppendText("The second item") paragraph.ApplyStyle(BuiltinStyle.Heading1) paragraph.ListFormat.ApplyStyle("levelstyle") paragraph = section.AddParagraph() paragraph.AppendText("The first sub-item") paragraph.ApplyStyle(BuiltinStyle.Heading2) paragraph.ListFormat.ListLevelNumber = 1 paragraph.ListFormat.ApplyStyle("levelstyle") paragraph = section.AddParagraph() paragraph.AppendText("The second sub-item") paragraph.ApplyStyle(BuiltinStyle.Heading2) paragraph.ListFormat.ContinueListNumbering() paragraph.ListFormat.ApplyStyle("levelstyle") paragraph = section.AddParagraph() paragraph.AppendText("A sub-sub-item") paragraph.ApplyStyle(BuiltinStyle.Heading5) paragraph.ListFormat.ListLevelNumber = 2 paragraph.ListFormat.ApplyStyle("levelstyle") paragraph = section.AddParagraph() paragraph.AppendText("The third item") paragraph.ApplyStyle(BuiltinStyle.Heading1) paragraph.ListFormat.ApplyStyle("levelstyle") document.SaveToFile("result.docx", FileFormat.Docx) End Sub End Class End Namespace
以上便是通過Spire.Doc將Doc轉(zhuǎn)換為PDF時如何使用卸載的字體的教程,如果您有其他問題也可以繼續(xù)瀏覽本系列文章,獲取相關(guān)教程,你還可以給我留言或者加入我們的官方技術(shù)交流群。
歡迎下載|體驗更多E-iceblue產(chǎn)品
獲取更多信息請咨詢慧都在線客服 ;技術(shù)交流Q群(767755948)