Generating nested numbered list

Posted by Yesi under C# on 4/10/2015 | Points: 10 | Views : 1403 | Status : [Member] | Replies : 1
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




Responses

Posted by: Hitu on: 4/13/2015 [Member] Starter | Points: 25

Up
0
Down
You can learn from this tutorials http://www.e-iceblue.com/Knowledgebase/Spire.Doc/Spire.Doc-Program-Guide/Paragraph/How-to-Create-Multi-level-List-Numbering-in-Word-in-C-VB.NET.html .
Define a new multi-level list style, create a paragraph, append text to paragraph and apply the paragraph style with Heading1,and then repeat.
Document document = new Document();
Section section = document.AddSection();

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);

Paragraph paragraph = section.AddParagraph();
paragraph.AppendText("The first item");
paragraph.ApplyStyle(BuiltinStyle.Heading1);
paragraph.ListFormat.ApplyStyle("levelstyle");

paragraph = section.AddParagraph();
paragraph.AppendText("The second item");
paragraph.ApplyStyle(BuiltinStyle.Heading1);
paragraph.ListFormat.ApplyStyle("levelstyle");

paragraph = section.AddParagraph();
paragraph.AppendText("The first sub-item");
paragraph.ApplyStyle(BuiltinStyle.Heading2);
paragraph.ListFormat.ListLevelNumber = 1;
paragraph.ListFormat.ApplyStyle("levelstyle");

paragraph = section.AddParagraph();
paragraph.AppendText("The second sub-item");
paragraph.ApplyStyle(BuiltinStyle.Heading2);
paragraph.ListFormat.ContinueListNumbering();
paragraph.ListFormat.ApplyStyle("levelstyle");

paragraph = section.AddParagraph();
paragraph.AppendText("A sub-sub-item");
paragraph.ApplyStyle(BuiltinStyle.Heading5);
paragraph.ListFormat.ListLevelNumber = 2;
paragraph.ListFormat.ApplyStyle("levelstyle");

paragraph = section.AddParagraph();
paragraph.AppendText("The third item");
paragraph.ApplyStyle(BuiltinStyle.Heading1);
paragraph.ListFormat.ApplyStyle("levelstyle");

document.SaveToFile(@"result.docx", FileFormat.Docx);


Yesi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response