翻譯|使用教程|編輯:顏馨|2023-05-23 09:38:50.960|閱讀 146 次
概述:本章介紹如何在 Word 文檔中插入列表,歡迎查閱~
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發人員無需安裝 Microsoft Word情況下,輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業開發經驗Spire系列辦公文檔開發工具,專注于創建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團隊研發,不依賴第三方軟件,不受其他國家的技術或法律法規限制,同時適配國產操作系統如中科方德、中標麒麟等,兼容國產文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
技術交流Q群(767755948)
Word 文檔中使用列表來勾勒、排列和強調文本,使用戶能夠輕松掃描和理解一系列項目。Word中有三種不同類型的列表,即編號列表,項目符號列表和多級列表。編號列表用于具有序列或優先級的項目,例如一系列說明。項目符號列表用于沒有特定優先級的項目,例如函數或事實列表。多級列表用于存在序列且您希望每個段落單獨編號的情況。
Spire.Doc for .NET 提供了 ListStyle 類,可用于創建編號列表樣式或項目符號樣式。然后,可以使用 Paragraph.ListFormat.ApplyStyle() 方法將列表樣式應用于段落。創建編號列表的步驟如下。
【C# 】
using Spire.Doc; using Spire.Doc.Documents; namespace CreateOrderedList { class Program { static void Main(string[] args) { //Create a Document object Document document = new Document(); //Add a section Section section = document.AddSection(); //Create a numbered list style ListStyle listStyle = new ListStyle(document, ListType.Numbered); listStyle.Name = "numberedList"; listStyle.Levels[0].PatternType = ListPatternType.DecimalEnclosedParen; listStyle.Levels[0].TextPosition = 20; document.ListStyles.Add(listStyle); //Add a paragraph Paragraph paragraph = section.AddParagraph(); paragraph.AppendText("Required Web Development Skills:"); paragraph.Format.AfterSpacing = 5f; //Add a paragraph and apply the numbered list style to it paragraph = section.AddParagraph(); paragraph.AppendText("HTML"); paragraph.ListFormat.ApplyStyle("numberedList"); paragraph.ListFormat.ListLevelNumber = 0; //Add another four paragraphs and apply the numbered list style to them paragraph = section.AddParagraph(); paragraph.AppendText("CSS"); paragraph.ListFormat.ApplyStyle("numberedList"); paragraph.ListFormat.ListLevelNumber = 0; paragraph = section.AddParagraph(); paragraph.AppendText("JavaScript"); paragraph.ListFormat.ApplyStyle("numberedList"); paragraph.ListFormat.ListLevelNumber = 0; paragraph = section.AddParagraph(); paragraph.AppendText("Python"); paragraph.ListFormat.ApplyStyle("numberedList"); paragraph.ListFormat.ListLevelNumber = 0; paragraph = section.AddParagraph(); paragraph.AppendText("MySQL"); paragraph.ListFormat.ApplyStyle("numberedList"); paragraph.ListFormat.ListLevelNumber = 0; //Save the document to file document.SaveToFile("NumberedList.docx", FileFormat.Docx); } } }
【VB.NET】
Imports Spire.Doc Imports Spire.Doc.Documents Namespace CreateOrderedList Class Program Shared Sub Main(ByVal args() As String) 'Create a Document object Dim document As Document = New Document() 'Add a section Dim section As Section = document.AddSection() 'Create a numbered list style Dim listStyle As ListStyle = New ListStyle(document,ListType.Numbered) listStyle.Name = "numberedList" listStyle.Levels(0).PatternType = ListPatternType.DecimalEnclosedParen listStyle.Levels(0).TextPosition = 20 document.ListStyles.Add(listStyle) 'Add a paragraph Dim paragraph As Paragraph = section.AddParagraph() paragraph.AppendText("Required Web Development Skills:") paragraph.Format.AfterSpacing = 5f 'Add a paragraph and apply the numbered list style to it paragraph = section.AddParagraph() paragraph.AppendText("HTML") paragraph.ListFormat.ApplyStyle("numberedList") paragraph.ListFormat.ListLevelNumber = 0 'Add another four paragraphs and apply the numbered list style to them paragraph = section.AddParagraph() paragraph.AppendText("CSS") paragraph.ListFormat.ApplyStyle("numberedList") paragraph.ListFormat.ListLevelNumber = 0 paragraph = section.AddParagraph() paragraph.AppendText("JavaScript") paragraph.ListFormat.ApplyStyle("numberedList") paragraph.ListFormat.ListLevelNumber = 0 paragraph = section.AddParagraph() paragraph.AppendText("Python") paragraph.ListFormat.ApplyStyle("numberedList") paragraph.ListFormat.ListLevelNumber = 0 paragraph = section.AddParagraph() paragraph.AppendText("MySQL") paragraph.ListFormat.ApplyStyle("numberedList") paragraph.ListFormat.ListLevelNumber = 0 'Save the document to file document.SaveToFile("NumberedList.docx", FileFormat.Docx) End Sub End Class End Namespace
創建項目符號列表的過程類似于創建編號列表的過程。不同之處在于,在創建列表樣式時,必須將列表類型指定為"項目符號",并為其設置項目符號。以下是詳細步驟。
【C# 】
using Spire.Doc; using Spire.Doc.Documents; namespace CreateUnorderedList { class Program { static void Main(string[] args) { //Create a Document object Document document = new Document(); //Add a section Section section = document.AddSection(); //Create a bulleted list style ListStyle listStyle = new ListStyle(document, ListType.Bulleted); listStyle.Name = "bulletedList"; listStyle.Levels[0].BulletCharacter = "\x00B7"; listStyle.Levels[0].CharacterFormat.FontName = "Symbol"; listStyle.Levels[0].TextPosition = 20; document.ListStyles.Add(listStyle); //Add a paragraph Paragraph paragraph = section.AddParagraph(); paragraph.AppendText("Computer Science Subjects:"); paragraph.Format.AfterSpacing = 5f; //Add a paragraph and apply the bulleted list style to it paragraph = section.AddParagraph(); paragraph.AppendText("Data Structure"); paragraph.ListFormat.ApplyStyle("bulletedList"); paragraph.ListFormat.ListLevelNumber = 0; //Add another five paragraphs and apply the bulleted list style to them paragraph = section.AddParagraph(); paragraph.AppendText("Algorithm"); paragraph.ListFormat.ApplyStyle("bulletedList"); paragraph.ListFormat.ListLevelNumber = 0; paragraph = section.AddParagraph(); paragraph.AppendText("Computer Networks"); paragraph.ListFormat.ApplyStyle("bulletedList"); paragraph.ListFormat.ListLevelNumber = 0; paragraph = section.AddParagraph(); paragraph.AppendText("Operating System"); paragraph.ListFormat.ApplyStyle("bulletedList"); paragraph.ListFormat.ListLevelNumber = 0; paragraph = section.AddParagraph(); paragraph.AppendText("C Programming"); paragraph.ListFormat.ApplyStyle("bulletedList"); paragraph.ListFormat.ListLevelNumber = 0; paragraph = section.AddParagraph(); paragraph.AppendText("Theory of Computations"); paragraph.ListFormat.ApplyStyle("bulletedList"); paragraph.ListFormat.ListLevelNumber = 0; //Save the document to file document.SaveToFile("BulletedList.docx", FileFormat.Docx); } } }
【VB.NET】
Imports Spire.Doc Imports Spire.Doc.Documents Namespace CreateUnorderedList Class Program Shared Sub Main(ByVal args() As String) 'Create a Document object Dim document As Document = New Document() 'Add a section Dim section As Section = document.AddSection() 'Create a bulleted list style Dim listStyle As ListStyle = New ListStyle(document,ListType.Bulleted) listStyle.Name = "bulletedList" listStyle.Levels(0).BulletCharacter = "\x00B7" listStyle.Levels(0).CharacterFormat.FontName = "Symbol" listStyle.Levels(0).TextPosition = 20 document.ListStyles.Add(listStyle) 'Add a paragraph Dim paragraph As Paragraph = section.AddParagraph() paragraph.AppendText("Computer Science Subjects:") paragraph.Format.AfterSpacing = 5f 'Add a paragraph and apply the bulleted list style to it paragraph = section.AddParagraph() paragraph.AppendText("Data Structure") paragraph.ListFormat.ApplyStyle("bulletedList") paragraph.ListFormat.ListLevelNumber = 0 'Add another five paragraphs and apply the bulleted list style to them paragraph = section.AddParagraph() paragraph.AppendText("Algorithm") paragraph.ListFormat.ApplyStyle("bulletedList") paragraph.ListFormat.ListLevelNumber = 0 paragraph = section.AddParagraph() paragraph.AppendText("Computer Networks") paragraph.ListFormat.ApplyStyle("bulletedList") paragraph.ListFormat.ListLevelNumber = 0 paragraph = section.AddParagraph() paragraph.AppendText("Operating System") paragraph.ListFormat.ApplyStyle("bulletedList") paragraph.ListFormat.ListLevelNumber = 0 paragraph = section.AddParagraph() paragraph.AppendText("C Programming") paragraph.ListFormat.ApplyStyle("bulletedList") paragraph.ListFormat.ListLevelNumber = 0 paragraph = section.AddParagraph() paragraph.AppendText("Theory of Computations") paragraph.ListFormat.ApplyStyle("bulletedList") paragraph.ListFormat.ListLevelNumber = 0 'Save the document to file document.SaveToFile("BulletedList.docx", FileFormat.Docx) End Sub End Class End Namespace
多級列表至少包含兩個不同的級別。嵌套列表的每個級別都由 ListStyle.Levels[index] 屬性表示,通過該屬性可以設置特定級別的編號類型和前綴。以下是在 Word 中創建多級編號列表的步驟。
【C# 】
using Spire.Doc; using Spire.Doc.Documents; namespace CreateMultiLevelList { class Program { static void Main(string[] args) { //Create a Document object Document document = new Document(); //Add a section Section section = document.AddSection(); //Create a numbered list style, specifying number prefix and pattern type of each level ListStyle listStyle = new ListStyle(document, ListType.Numbered); listStyle.Name = "levelstyle"; listStyle.Levels[0].PatternType = ListPatternType.Arabic; listStyle.Levels[0].TextPosition = 20; 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); //Add a paragraph Paragraph paragraph = section.AddParagraph(); paragraph.AppendText("Here's a Multi-Level Numbered List:"); paragraph.Format.AfterSpacing = 5f; //Add a paragraph and apply the numbered list style to it paragraph = section.AddParagraph(); paragraph.AppendText("The first item"); paragraph.ListFormat.ApplyStyle("levelstyle"); paragraph.ListFormat.ListLevelNumber = 0; //Add another five paragraphs and apply the numbered list stype to them paragraph = section.AddParagraph(); paragraph.AppendText("The second item"); paragraph.ListFormat.ApplyStyle("levelstyle"); paragraph.ListFormat.ListLevelNumber = 0; paragraph = section.AddParagraph(); paragraph.AppendText("The first sub-item"); paragraph.ListFormat.ApplyStyle("levelstyle"); paragraph.ListFormat.ListLevelNumber = 1; paragraph = section.AddParagraph(); paragraph.AppendText("The second sub-item"); paragraph.ListFormat.ContinueListNumbering(); paragraph.ListFormat.ApplyStyle("levelstyle"); paragraph = section.AddParagraph(); paragraph.AppendText("A sub-sub-item"); paragraph.ListFormat.ApplyStyle("levelstyle"); paragraph.ListFormat.ListLevelNumber = 2; paragraph = section.AddParagraph(); paragraph.AppendText("The third item"); paragraph.ListFormat.ApplyStyle("levelstyle"); paragraph.ListFormat.ListLevelNumber = 0; //Save the document to file document.SaveToFile("MultilevelNumberedList.docx", FileFormat.Docx); } } }
【VB.NET】
Imports Spire.Doc Imports Spire.Doc.Documents Namespace CreateMultiLevelList Class Program Shared Sub Main(ByVal args() As String) 'Create a Document object Dim document As Document = New Document() 'Add a section Dim section As Section = document.AddSection() 'Create a numbered list style, specifying number prefix and pattern type of each level Dim listStyle As ListStyle = New ListStyle(document,ListType.Numbered) listStyle.Name = "levelstyle" listStyle.Levels(0).PatternType = ListPatternType.Arabic listStyle.Levels(0).TextPosition = 20 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) 'Add a paragraph Dim paragraph As Paragraph = section.AddParagraph() paragraph.AppendText("Here's a Multi-Level Numbered List:") paragraph.Format.AfterSpacing = 5f 'Add a paragraph and apply the numbered list style to it paragraph = section.AddParagraph() paragraph.AppendText("The first item") paragraph.ListFormat.ApplyStyle("levelstyle") paragraph.ListFormat.ListLevelNumber = 0 'Add another five paragraphs and apply the numbered list stype to them paragraph = section.AddParagraph() paragraph.AppendText("The second item") paragraph.ListFormat.ApplyStyle("levelstyle") paragraph.ListFormat.ListLevelNumber = 0 paragraph = section.AddParagraph() paragraph.AppendText("The first sub-item") paragraph.ListFormat.ApplyStyle("levelstyle") paragraph.ListFormat.ListLevelNumber = 1 paragraph = section.AddParagraph() paragraph.AppendText("The second sub-item") paragraph.ListFormat.ContinueListNumbering() paragraph.ListFormat.ApplyStyle("levelstyle") paragraph = section.AddParagraph() paragraph.AppendText("A sub-sub-item") paragraph.ListFormat.ApplyStyle("levelstyle") paragraph.ListFormat.ListLevelNumber = 2 paragraph = section.AddParagraph() paragraph.AppendText("The third item") paragraph.ListFormat.ApplyStyle("levelstyle") paragraph.ListFormat.ListLevelNumber = 0 'Save the document to file document.SaveToFile("MultilevelNumberedList.docx", FileFormat.Docx) End Sub End Class End Namespace
在某些情況下,您可能希望在多級列表中混合使用數字和符號項目符號點。要創建混合類型列表,您只需創建編號列表樣式和項目符號列表樣式,并將它們應用于不同的段落。具體步驟如下。
【C# 】
using Spire.Doc; using Spire.Doc.Documents; namespace CreateMultilevelMixedList { class Program { static void Main(string[] args) { //Create a Document object Document document = new Document(); //Add a section Section section = document.AddSection(); //Create a numbered list style ListStyle numberedListStyle = new ListStyle(document, ListType.Numbered); numberedListStyle.Name = "numberedStyle"; numberedListStyle.Levels[0].PatternType = ListPatternType.Arabic; numberedListStyle.Levels[0].TextPosition = 20; numberedListStyle.Levels[1].PatternType = ListPatternType.LowLetter; document.ListStyles.Add(numberedListStyle); //Create a bulleted list style ListStyle bulletedListStyle = new ListStyle(document, ListType.Bulleted); bulletedListStyle.Name = "bulltedStyle"; bulletedListStyle.Levels[2].BulletCharacter = "\x002A"; bulletedListStyle.Levels[2].CharacterFormat.FontName = "Symbol"; document.ListStyles.Add(bulletedListStyle); //Add a paragraph Paragraph paragraph = section.AddParagraph(); paragraph.AppendText("Here's a Multi-Level Mixed List:"); paragraph.Format.AfterSpacing = 5f; //Add a paragraph and apply the numbered list style to it paragraph = section.AddParagraph(); paragraph.AppendText("The first item"); paragraph.ListFormat.ApplyStyle("numberedStyle"); paragraph.ListFormat.ListLevelNumber = 0; //Add another five paragraphs and apply different list stype to them paragraph = section.AddParagraph(); paragraph.AppendText("The first sub-item"); paragraph.ListFormat.ApplyStyle("numberedStyle"); paragraph.ListFormat.ListLevelNumber = 1; paragraph = section.AddParagraph(); paragraph.AppendText("The second sub-item"); paragraph.ListFormat.ListLevelNumber = 1; paragraph.ListFormat.ApplyStyle("numberedStyle"); paragraph = section.AddParagraph(); paragraph.AppendText("The first sub-sub-item"); paragraph.ListFormat.ApplyStyle("bulltedStyle"); paragraph.ListFormat.ListLevelNumber = 2; paragraph = section.AddParagraph(); paragraph.AppendText("The second sub-sub-item"); paragraph.ListFormat.ApplyStyle("bulltedStyle"); paragraph.ListFormat.ListLevelNumber = 2; paragraph = section.AddParagraph(); paragraph.AppendText("The second item"); paragraph.ListFormat.ApplyStyle("numberedStyle"); paragraph.ListFormat.ListLevelNumber = 0; //Save the document to file document.SaveToFile("MultilevelMixedList.docx", FileFormat.Docx); } } }
【VB.NET】
Imports Spire.Doc Imports Spire.Doc.Documents Namespace CreateMultilevelMixedList Class Program Shared Sub Main(ByVal args() As String) 'Create a Document object Dim document As Document = New Document() 'Add a section Dim section As Section = document.AddSection() 'Create a numbered list style Dim numberedListStyle As ListStyle = New ListStyle(document,ListType.Numbered) numberedListStyle.Name = "numberedStyle" numberedListStyle.Levels(0).PatternType = ListPatternType.Arabic numberedListStyle.Levels(0).TextPosition = 20 numberedListStyle.Levels(1).PatternType = ListPatternType.LowLetter document.ListStyles.Add(numberedListStyle) 'Create a bulleted list style Dim bulletedListStyle As ListStyle = New ListStyle(document,ListType.Bulleted) bulletedListStyle.Name = "bulltedStyle" bulletedListStyle.Levels(2).BulletCharacter = "\x002A" bulletedListStyle.Levels(2).CharacterFormat.FontName = "Symbol" document.ListStyles.Add(bulletedListStyle) 'Add a paragraph Dim paragraph As Paragraph = section.AddParagraph() paragraph.AppendText("Here's a Multi-Level Mixed List:") paragraph.Format.AfterSpacing = 5f 'Add a paragraph and apply the numbered list style to it paragraph = section.AddParagraph() paragraph.AppendText("The first item") paragraph.ListFormat.ApplyStyle("numberedStyle") paragraph.ListFormat.ListLevelNumber = 0 'Add another five paragraphs and apply different list stype to them paragraph = section.AddParagraph() paragraph.AppendText("The first sub-item") paragraph.ListFormat.ApplyStyle("numberedStyle") paragraph.ListFormat.ListLevelNumber = 1 paragraph = section.AddParagraph() paragraph.AppendText("The second sub-item") paragraph.ListFormat.ListLevelNumber = 1 paragraph.ListFormat.ApplyStyle("numberedStyle") paragraph = section.AddParagraph() paragraph.AppendText("The first sub-sub-item") paragraph.ListFormat.ApplyStyle("bulltedStyle") paragraph.ListFormat.ListLevelNumber = 2 paragraph = section.AddParagraph() paragraph.AppendText("The second sub-sub-item") paragraph.ListFormat.ApplyStyle("bulltedStyle") paragraph.ListFormat.ListLevelNumber = 2 paragraph = section.AddParagraph() paragraph.AppendText("The second item") paragraph.ListFormat.ApplyStyle("numberedStyle") paragraph.ListFormat.ListLevelNumber = 0 'Save the document to file document.SaveToFile("MultilevelMixedList.docx", FileFormat.Docx) End Sub End Class End Namespace
以上便是如何在 Word 文檔中插入列表的教程,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群。
歡迎下載|體驗更多E-iceblue產品
獲取更多信息請咨詢 ;技術交流Q群(767755948)
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn