Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Feb 20, 2015 2:42 pm

Can someone please guide on how to generate nested number list.

Need to generate:
1. One
2. Two
2.1 TwoPointOne
2.2 TwoPointTwo
2.2.1 TwoTwoOne
3. Three

rupen.anjaria@gmail.com
 
Posts: 3
Joined: Fri Feb 20, 2015 2:40 pm

Mon Feb 23, 2015 9:32 am

Hello,

Please try the following code to generate the nested numbered list.
Code: Select all
//create a new doc document
            Document document = new Document();
            //add one section
            Section section = document.AddSection();
            //Create a new paragraph

            ListStyle listStyle = new ListStyle(document, 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;
            document.ListStyles.Add(listStyle);

            //apply the custom style
            Paragraph paragraph = section.AddParagraph();
            paragraph.AppendText("One");
            paragraph.ListFormat.ApplyStyle("levelstyle");

            paragraph = section.AddParagraph();
            paragraph.AppendText("Two");
            paragraph.ListFormat.ApplyStyle("levelstyle");

            paragraph = section.AddParagraph();
            paragraph.AppendText("TwoPointOne");
            paragraph.ListFormat.ListLevelNumber = 1;
            paragraph.ListFormat.ApplyStyle("levelstyle");

            paragraph = section.AddParagraph();
            paragraph.AppendText("TwoPointTwo");
            paragraph.ListFormat.ContinueListNumbering();
            paragraph.ListFormat.ApplyStyle("levelstyle");

            paragraph = section.AddParagraph();
            paragraph.AppendText("TwoTwoOne");
            paragraph.ListFormat.ListLevelNumber = 2;
            paragraph.ListFormat.ApplyStyle("levelstyle");

            paragraph = section.AddParagraph();
            paragraph.AppendText("Three");
            paragraph.ListFormat.ApplyStyle("levelstyle");

            //Save doc file.
            document.SaveToFile(@"result.docx", FileFormat.Docx);


Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Fri Feb 27, 2015 6:52 am

Hello,

Have you tried the method? Does it fulfill your needs? Could you please give us some feedback at your convenience?

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Mon Mar 02, 2015 7:58 am

I am going to try your method today. I will reply accordingly. Thank you.

rupen.anjaria@gmail.com
 
Posts: 3
Joined: Fri Feb 20, 2015 2:40 pm

Tue Mar 03, 2015 3:00 pm

Yes, this seems to be working and is giving the exact behavior.

Thanks a lot!!! :D

rupen.anjaria@gmail.com
 
Posts: 3
Joined: Fri Feb 20, 2015 2:40 pm

Wed Mar 04, 2015 1:38 am

Hello,

Thanks for your response. Please contact us If you have any questions or needs.

Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.Doc