C # Create a Word project label list, multilevel numbered list

Source: Internet
Author: User

In a Word document, when you have multiple, side-by-side information content or paragraphs, we often organize the document in the form of adding item labels, and the document is more aesthetically pleasing to read. In addition, for content with a certain level of logic, you can also use a multilevel numbered list to indicate the level of document content, and also add flexibility when modifying and editing documents. Therefore, in this document, you will learn how to create a project numbered list and a multilevel numbered list in C # by using the class library free Spire.doc. NET.

using the tool : Free spire.doc for. NET (Community Edition)

How to use : After you install the class library, reference Spire.Doc.dll in the project (DLL files can be obtained in the Bin folder under the installation path)

Create a list of project labels
Using spire.doc;using Spire.doc.documents;namespace wordbullets{class Program {static void Main (string[] ar            GS) {//Initialize the document class instance and add section Document doc = new Document (); Section section = Doc.            AddSection (); Add seven paragraphs and add the text separately Paragraph para1 = section.            Addparagraph (); Para1.            AppendText ("International Political organization"); Paragraph para2 = section.            Addparagraph (); Para2.            AppendText ("European Union (EU)"); Paragraph para3 = section.            Addparagraph (); Para3.            AppendText ("Commonwealth of Independent States (CIS)"); Paragraph para4 = section.            Addparagraph (); Para4.            AppendText ("Shanghai Cooperation Organization"); Paragraph para5 = section.            Addparagraph (); Para5.            AppendText ("League of Arab Conferences"); Paragraph para6 = section.            Addparagraph (); Para6.            AppendText ("International Organization for Eco-Security cooperation"); Paragraph para7 = section.            Addparagraph (); Para7.            AppendText ("League of Arab States"); Create paragraph format (font) Paragraphstyle sTyle = new Paragraphstyle (DOC); Style.            Name = "FontStyle"; Style.            Characterformat.fontname = "Song Body"; Style.            Characterformat.fontsize = 12f; Doc.            Styles.add (style); Traverse all paragraphs for (int i = 0; i < sections. Paragraphs.count; i++) {//Apply bullets from the second paragraph to arrange if (i! = 0) {SECTION.P Aragraphs[i].                ApplyStyle (Builtinstyle.listbullet2); }//Apply font formatting to each section. Paragraphs[i].            ApplyStyle ("FontStyle"); }//Save and open document Doc.            SaveToFile ("Project list. docx", fileformat.docx2013);        System.Diagnostics.Process.Start ("Project list. docx"); }    }}

Test results:

Second, create a multilevel numbered list
Using spire.doc;using spire.doc.documents;using Spire.doc.fields;namespace multi_levellist_doc{class Program {            static void Main (string[] args) {//new Word Document DOC = new document (); Section section = Doc.            AddSection ();            Initializes the ListStyle object, specifying the list type as a numeric listing and naming liststyle ListStyle = new ListStyle (doc, listtype.numbered);            Liststyle.name = "Levelstyle"; Set the level list mode to Arabic numerals liststyle.levels[0].            Patterntype = Listpatterntype.arabic; Set level two list number prefix and mode liststyle.levels[1].            Numberprefix = "\x0000."; LISTSTYLE.LEVELS[1].            Patterntype = Listpatterntype.arabic; Set level three list number prefix and mode liststyle.levels[2].            Numberprefix = "\x0000.\x0001."; LISTSTYLE.LEVELS[2].            Patterntype = Listpatterntype.arabic; In the ListStyles collection, add the new list style doc.            Liststyles.add (ListStyle); Create font format Spire.Doc.Formatting.CharacterFormat FOrmat = new Spire.Doc.Formatting.CharacterFormat (DOC); Format.            FontName = "Song Body"; To add a paragraph, set the first-order sequence Paragraph Paragraph = section.            Addparagraph (); TextRange TR = paragraph.            AppendText ("main organization"); Tr. Applycharacterformat (format); Apply font format paragraph. ApplyStyle (BUILTINSTYLE.HEADING1); Apply the Heading 1 style paragraph. Listformat.applystyle ("Levelstyle"); Apply list style//Add paragraph, set first order sequence paragraph = section.            Addparagraph (); TR = paragraph.            AppendText ("main functions"); Tr.            Applycharacterformat (format); Paragraph.            ApplyStyle (BUILTINSTYLE.HEADING1); Paragraph.            Listformat.applystyle ("Levelstyle"); To add a paragraph, set the two-level sequence paragraph = section.            Addparagraph (); TR = paragraph.            AppendText ("basic functions"); Tr.            Applycharacterformat (format); Paragraph.            ApplyStyle (BUILTINSTYLE.HEADING2); Paragraph. Listformat.listlevelnumber = 1; Set the rank to second level paragraph. ListFormat.applystyle ("Levelstyle"); To add a paragraph, set the two-level sequence paragraph = section.            Addparagraph (); TR = paragraph.            AppendText ("5 major functions"); Tr.            Applycharacterformat (format); Paragraph.            ApplyStyle (BUILTINSTYLE.HEADING2); Paragraph.            Listformat.continuelistnumbering (); Paragraph.            Listformat.applystyle ("Levelstyle"); To add a paragraph, set the three-level sequence paragraph = section.            Addparagraph (); TR = paragraph.            AppendText ("the management function \ \ \ \ \ \ \ \ \ \ ' function ') Tr.            Applycharacterformat (format); Paragraph.            ApplyStyle (BUILTINSTYLE.HEADING5); Paragraph. Listformat.listlevelnumber = 2; Set the level to third level paragraph.            Listformat.applystyle ("Levelstyle"); To add a paragraph, set the first-order sequence paragraph = section.            Addparagraph (); TR = paragraph.            AppendText ("Basic Principles"); Tr.            Applycharacterformat (format); Paragraph.            ApplyStyle (BUILTINSTYLE.HEADING1); Paragraph. Listformat.applystyle ("Levelstyle"); Save and open document Doc.            SaveToFile ("Multilevel list. docx", fileformat.docx);        System.Diagnostics.Process.Start ("Multilevel list. docx"); }    }}

Test results:

The above code for reference, welcome reprint (Reproduced please indicate the source).

Thanks for reading!

C # Create a Word project label list, multilevel numbered list

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.