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
usingSpire.doc;usingSpire.Doc.Documents;namespacewordbullets{classProgram {Static voidMain (string[] args) {            //Initializes an instance of the document class and adds a sectionDocument doc =NewDocument (); Section Section=Doc.            AddSection (); //add seven paragraphs and add text separatelyParagraph para1 =Section .            Addparagraph (); Para1. AppendText ("International political Organizations"); 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 formatting (font)Paragraphstyle style =NewParagraphstyle (DOC); Style. Name="FontStyle"; Style. Characterformat.fontname="Song Body"; Style. Characterformat.fontsize=12f; Doc.            Styles.add (style); //Traverse all paragraphs             for(inti =0; I < section. Paragraphs.count; i++)            {                //apply bullet arrangement starting from the second paragraph                if(I! =0) {section. Paragraphs[i].                ApplyStyle (Builtinstyle.listbullet2); }                //apply font formatting to each paragraphSection. Paragraphs[i]. ApplyStyle ("FontStyle"); }            //Save and open a documentDoc. SaveToFile ("list of items. docx", fileformat.docx2013); System.Diagnostics.Process.Start ("list of items. docx"); }    }}

Test results:

Second, create a multilevel numbered list
usingSpire.doc;usingSpire.Doc.Documents;usingSpire.Doc.Fields;namespacemulti_levellist_doc{classProgram {Static voidMain (string[] args) {            //Create a new Word documentDocument doc =NewDocument (); Section Section=Doc.            AddSection (); //initializes the ListStyle object, specifying that the list type is a numeric listing and namedListStyle ListStyle =NewListStyle (Doc, listtype.numbered); Liststyle.name="Levelstyle"; //Set level list mode to Arabic numeralsliststyle.levels[0]. Patterntype =listpatterntype.arabic; //Set level Two list number prefixes and patternsliststyle.levels[1]. Numberprefix ="\x0000."; liststyle.levels[1]. Patterntype =listpatterntype.arabic; //Set Level Three list number prefixes and patternsliststyle.levels[2]. Numberprefix ="\x0000.\x0001."; liststyle.levels[2]. Patterntype =listpatterntype.arabic; //Add a new list style to the ListStyles collectionDoc.            Liststyles.add (ListStyle); //Create font formatSpire.Doc.Formatting.CharacterFormat format =NewSpire.Doc.Formatting.CharacterFormat (DOC); Format. FontName="Song Body"; //add a paragraph, set a sequence of levelsParagraph Paragraph =Section .            Addparagraph (); TextRange TR= paragraph. AppendText ("main Organizational Structure"); Tr. Applycharacterformat (format); //Apply font formattingParagraph. ApplyStyle (BUILTINSTYLE.HEADING1);//Apply the Heading 1 styleParagraph. Listformat.applystyle ("Levelstyle");//Apply List Style//add a paragraph, set a sequence of levelsParagraph =Section .            Addparagraph (); TR= paragraph. AppendText ("main Functions"); Tr.            Applycharacterformat (format); Paragraph.            ApplyStyle (BUILTINSTYLE.HEADING1); Paragraph. Listformat.applystyle ("Levelstyle"); //add a paragraph, set a level two sequenceParagraph =Section .            Addparagraph (); TR= paragraph. AppendText ("Basic Functions"); Tr.            Applycharacterformat (format); Paragraph.            ApplyStyle (BUILTINSTYLE.HEADING2); Paragraph. Listformat.listlevelnumber=1;//set level to second levelParagraph. Listformat.applystyle ("Levelstyle"); //add a paragraph, set a level two sequenceParagraph =Section .            Addparagraph (); TR= paragraph. AppendText ("5 Major functions"); Tr.            Applycharacterformat (format); Paragraph.            ApplyStyle (BUILTINSTYLE.HEADING2); Paragraph.            Listformat.continuelistnumbering (); Paragraph. Listformat.applystyle ("Levelstyle"); //add a paragraph, set a level three sequenceParagraph =Section .            Addparagraph (); TR= paragraph. AppendText ("management functions \ n organizational functions \ n coordinating functions \ n regulating functions \ n providing functions"); Tr.            Applycharacterformat (format); Paragraph.            ApplyStyle (BUILTINSTYLE.HEADING5); Paragraph. Listformat.listlevelnumber=2;//set level to third levelParagraph. Listformat.applystyle ("Levelstyle"); //add a paragraph, set a sequence of levelsParagraph =Section .            Addparagraph (); TR= paragraph. AppendText ("Basic Principles"); Tr.            Applycharacterformat (format); Paragraph.            ApplyStyle (BUILTINSTYLE.HEADING1); Paragraph. Listformat.applystyle ("Levelstyle"); //Save and open a documentDoc. 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

Related Article

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.