日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C# 创建Word项目标号列表、多级编号列表

發布時間:2025/3/20 C# 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C# 创建Word项目标号列表、多级编号列表 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在Word文檔中,對于有多條并列的信息內容或者段落時,我們常以添加項目標號的形式來使文檔條理化,在閱讀時,文檔也更具美觀性。另外,對于在邏輯上存在一定層級結構的內容時,也可以通過多級編號列表來標明文檔內容的層次,并且,在修改、編輯文檔時也增加了靈活性。因此,在本篇文檔中,將介紹如何在C#中通過使用類庫Free Spire.Doc for .NET 來創建項目編號列表和多級編號列表的方法。

使用工具Free Spire.Doc for .NET(社區版)

使用方法:在安裝該類庫后,在項目中引用Spire.Doc.dll即可(dll文件可在安裝路徑下的Bin文件夾中獲取)

一、創建項目標號列表

using Spire.Doc; using Spire.Doc.Documents;namespace WordBullets {class Program{static void Main(string[] args){//初始化Document類實例,并添加sectionDocument doc = new Document();Section section = doc.AddSection();//添加七個段落并分別添加文字Paragraph para1 = section.AddParagraph();para1.AppendText("國際政治類組織");Paragraph para2 = section.AddParagraph();para2.AppendText("歐洲聯盟(歐盟)");Paragraph para3 = section.AddParagraph();para3.AppendText("獨立國家聯合體(獨聯體)");Paragraph para4 = section.AddParagraph();para4.AppendText("上海合作組織");Paragraph para5 = section.AddParagraph();para5.AppendText("阿拉伯會議聯盟");Paragraph para6 = section.AddParagraph();para6.AppendText("國際生態安全合作組織");Paragraph para7 = section.AddParagraph();para7.AppendText("阿拉伯國家聯盟");//創建段落格式(字體)ParagraphStyle style = new ParagraphStyle(doc);style.Name = "fontStyle";style.CharacterFormat.FontName = "宋體";style.CharacterFormat.FontSize = 12f;doc.Styles.Add(style);//遍歷所有段落for (int i = 0; i < section.Paragraphs.Count; i++){//從第二段開始應用項目符號排列if (i != 0){section.Paragraphs[i].ApplyStyle(BuiltinStyle.ListBullet2);}//應用字體格式到每一段section.Paragraphs[i].ApplyStyle("fontStyle");}//保存并打開文檔doc.SaveToFile("項目列表.docx", FileFormat.Docx2013);System.Diagnostics.Process.Start("項目列表.docx");}} }

測試效果:

二、創建多級編號列表

using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields;namespace Multi_levelList_Doc {class Program{static void Main(string[] args){//新建Word文檔Document doc = new Document();Section section = doc.AddSection();//初始化ListStyle對象,指定List類型為數字列表并命名ListStyle listStyle = new ListStyle(doc, 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;//在ListStyles集合中添加新建的list style doc.ListStyles.Add(listStyle);//創建字體格式Spire.Doc.Formatting.CharacterFormat format = new Spire.Doc.Formatting.CharacterFormat(doc);format.FontName = "宋體";//添加段落,設置一級序列Paragraph paragraph = section.AddParagraph();TextRange tr = paragraph.AppendText("主要組織機構");tr.ApplyCharacterFormat(format); //應用字體格式paragraph.ApplyStyle(BuiltinStyle.Heading1); //應用標題1樣式paragraph.ListFormat.ApplyStyle("levelstyle"); //應用列表樣式//添加段落,設置一級序列paragraph = section.AddParagraph();tr = paragraph.AppendText("主要職能");tr.ApplyCharacterFormat(format);paragraph.ApplyStyle(BuiltinStyle.Heading1);paragraph.ListFormat.ApplyStyle("levelstyle");//添加段落,設置二級序列paragraph = section.AddParagraph();tr = paragraph.AppendText("基本職能");tr.ApplyCharacterFormat(format);paragraph.ApplyStyle(BuiltinStyle.Heading2);paragraph.ListFormat.ListLevelNumber = 1; //設置等級為第二等級paragraph.ListFormat.ApplyStyle("levelstyle");//添加段落,設置二級序列paragraph = section.AddParagraph();tr = paragraph.AppendText("5大職能");tr.ApplyCharacterFormat(format);paragraph.ApplyStyle(BuiltinStyle.Heading2);paragraph.ListFormat.ContinueListNumbering();paragraph.ListFormat.ApplyStyle("levelstyle");//添加段落,設置三級序列paragraph = section.AddParagraph();tr = paragraph.AppendText("管理職能 \n 組織職能 \n 協調職能 \n 調節職能 \n 提供職能");tr.ApplyCharacterFormat(format);paragraph.ApplyStyle(BuiltinStyle.Heading5);paragraph.ListFormat.ListLevelNumber = 2; //設置等級為第三等級paragraph.ListFormat.ApplyStyle("levelstyle");//添加段落,設置一級序列paragraph = section.AddParagraph();tr = paragraph.AppendText("基本原則");tr.ApplyCharacterFormat(format);paragraph.ApplyStyle(BuiltinStyle.Heading1);paragraph.ListFormat.ApplyStyle("levelstyle");//保存并打開文檔doc.SaveToFile("多級列表.docx", FileFormat.Docx);System.Diagnostics.Process.Start("多級列表.docx");}} }

測試效果:

以上代碼供參考,歡迎轉載(轉載請注明出處)。

感謝閱讀!?

轉載于:https://www.cnblogs.com/Yesi/p/8658711.html

總結

以上是生活随笔為你收集整理的C# 创建Word项目标号列表、多级编号列表的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。