亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

使用C#代碼在Word文檔中插入列表的操作方法

 更新時間:2025年11月07日 09:15:27   作者:2501_93070778  
列表在 Word 文檔中用于概述、排列和強調(diào)文本,使用戶能夠輕松掃描和理解一系列項目,在本文中,您將學習如何使用 Spire.Doc for .NET 在 C# 和 VB.NET 中將這些類型的列表插入到 Word 文檔中,需要的朋友可以參考下

列表在 Word 文檔中用于概述、排列和強調(diào)文本,使用戶能夠輕松掃描和理解一系列項目。Word 中有三種不同類型的列表,分別是編號列表、項目符號列表和多級列表。編號列表用于表示具有順序或優(yōu)先級的項目,例如一系列的指示。項目符號列表用于表示沒有特定優(yōu)先級的項目,例如功能或事實列表。多級列表用于存在順序且希望每個段落單獨編號的情況。

在本文中,您將學習如何使用 Spire.Doc for .NET 在 C# 和 VB.NET 中將這些類型的列表插入到 Word 文檔中。

安裝 Spire.Doc for .NET

首先,您需要將 Spire.Doc for .NET 包中包含的 DLL 文件添加為 .NET 項目的引用。這些 DLL 文件可以通過此鏈接下載,或者通過 NuGet 安裝。

PM> Install-Package Spire.Doc

在 C# 和 VB.NET 中插入編號列表

Spire.Doc for .NET 提供了 ListStyle 類,您可以使用它來創(chuàng)建編號列表樣式或項目符號樣式。然后,可以通過 Paragraph.ListFormat.ApplyStyle() 方法將列表樣式應(yīng)用到段落中。

創(chuàng)建編號列表的示例代碼如下:

using Spire.Doc;
using Spire.Doc.Documents;
 
namespace CreateOrderedList
{
    class Program
    {
        static void Main(string[] args)
        {
            //創(chuàng)建一個 Document 對象
            Document document = new Document();
            
            //添加一個節(jié)
            Section section = document.AddSection();
 
            //創(chuàng)建一個編號列表樣式
            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);
 
            //添加一個段落
            Paragraph paragraph = section.AddParagraph();
            paragraph.AppendText("Required Web Development Skills:");
            paragraph.Format.AfterSpacing = 5f;
 
            //添加一個段落并應(yīng)用編號列表樣式
            paragraph = section.AddParagraph();
            paragraph.AppendText("HTML");
            paragraph.ListFormat.ApplyStyle("numberedList");
            paragraph.ListFormat.ListLevelNumber = 0;
 
            //添加另外四個段落并應(yīng)用編號列表樣式
            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;
 
            //保存結(jié)果文件
            document.SaveToFile("NumberedList.docx", FileFormat.Docx);
        }
    }
}

在 C# 和 VB.NET 中插入項目符號列表

創(chuàng)建項目符號列表的過程與創(chuàng)建編號列表類似。不同之處在于,在創(chuàng)建列表樣式時,必須將列表類型指定為“項目符號”,并為其設(shè)置一個項目符號符號。以下是相關(guān)代碼示例:

using Spire.Doc;
using Spire.Doc.Documents;
 
namespace CreateUnorderedList
{
    class Program
    {
        static void Main(string[] args)
        {
            //創(chuàng)建一個 Document 對象
            Document document = new Document();
 
            //添加一個節(jié)
            Section section = document.AddSection();
 
            //創(chuàng)建一個項目符號列表樣式
            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);
 
            //添加一個段落
            Paragraph paragraph = section.AddParagraph();
            paragraph.AppendText("Computer Science Subjects:");
            paragraph.Format.AfterSpacing = 5f;
 
            //添加一個段落并應(yīng)用項目符號列表樣式
            paragraph = section.AddParagraph();
            paragraph.AppendText("Data Structure");
            paragraph.ListFormat.ApplyStyle("bulletedList");
            paragraph.ListFormat.ListLevelNumber = 0;
 
            //添加另外五個段落并應(yīng)用項目符號列表樣式
            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;
 
            //保存結(jié)果文件
            document.SaveToFile("BulletedList.docx", FileFormat.Docx);
        }
    }
}

申請臨時許可證

如果您希望從生成的文檔中移除評估信息,或解除功能限制,請申請一份 30 天的試用許可證。

到此這篇關(guān)于使用C#代碼在Word文檔中插入列表的操作方法的文章就介紹到這了,更多相關(guān)C# Word插入列表內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論