ListCollectionAdd Method (ListTemplate) |
Namespace: Aspose.Words.Lists
Aspose.Words list templates correspond to the 21 list templates available in the Bullets and Numbering dialog box in Microsoft Word 2003.
All lists created using this method have 9 list levels.
List list = doc.Lists.Add(ListTemplate.NumberUppercaseLetterDot); Body body = doc.FirstSection.Body; foreach (Paragraph paragraph in body.Paragraphs.OfType<Paragraph>()) { paragraph.ListFormat.List = list; paragraph.ListFormat.ListLevelNumber = 1; }
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a numbered list based on one of the Microsoft Word list templates and // apply it to the current paragraph in the document builder builder.ListFormat.List = doc.Lists.Add(ListTemplate.NumberArabicDot); // There are 9 levels in this list, lets try them all for (int i = 0; i < 9; i++) { builder.ListFormat.ListLevelNumber = i; builder.Writeln("Level " + i); } // Create a bulleted list based on one of the Microsoft Word list templates // and apply it to the current paragraph in the document builder builder.ListFormat.List = doc.Lists.Add(ListTemplate.BulletDiamonds); // There are 9 levels in this list, lets try them all for (int i = 0; i < 9; i++) { builder.ListFormat.ListLevelNumber = i; builder.Writeln("Level " + i); } // This is a way to stop list formatting builder.ListFormat.List = null; builder.Document.Save(ArtifactsDir + "Lists.SpecifyListLevel.doc");
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a list based on a template List list1 = doc.Lists.Add(ListTemplate.NumberArabicParenthesis); // Modify the formatting of the list list1.ListLevels[0].Font.Color = Color.Red; list1.ListLevels[0].Alignment = ListLevelAlignment.Right; builder.Writeln("List 1 starts below:"); // Use the first list in the document for a while builder.ListFormat.List = list1; builder.Writeln("Item 1"); builder.Writeln("Item 2"); builder.ListFormat.RemoveNumbers(); // Now I want to reuse the first list, but need to restart numbering // This should be done by creating a copy of the original list formatting List list2 = doc.Lists.AddCopy(list1); // We can modify the new list in any way. Including setting new start number list2.ListLevels[0].StartAt = 10; // Use the second list in the document builder.Writeln("List 2 starts below:"); builder.ListFormat.List = list2; builder.Writeln("Item 1"); builder.Writeln("Item 2"); builder.ListFormat.RemoveNumbers(); builder.Document.Save(ArtifactsDir + "Lists.RestartNumberingUsingListCopy.doc");