Creates a new list based on a predefined template and adds it to the collection of lists in the document.
[Visual Basic]Overloads Public Function Add( _
ByVal
template As
ListTemplate _
) As
List Parameters
- template
- The template of the list.
Return Value
The newly created list.
Remarks
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.
Example
Creates new list formatting and applies it to a collection of paragraphs.
[C#]
List list = doc.Lists.Add(ListTemplate.NumberUppercaseLetterDot);
Body body = doc.FirstSection.Body;
foreach (Paragraph paragraph in body.Paragraphs)
{
paragraph.ListFormat.List = list;
paragraph.ListFormat.ListLevelNumber = 1;
}[Visual Basic]
Dim list As List = doc.Lists.Add(ListTemplate.NumberUppercaseLetterDot)
Dim body As Body = doc.FirstSection.Body
For Each paragraph As Paragraph In body.Paragraphs
paragraph.ListFormat.List = list
paragraph.ListFormat.ListLevelNumber = 1
Next paragraphShows how to specify list level number when building a list using DocumentBuilder.
[C#]
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(MyDir + "Lists.SpecifyListLevel Out.doc");[Visual Basic]
Dim doc As Document = New Document()
Dim builder As DocumentBuilder = 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 i As Integer = 0 To 8
builder.ListFormat.ListLevelNumber = i
builder.Writeln("Level " & i)
Next 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 i As Integer = 0 To 8
builder.ListFormat.ListLevelNumber = i
builder.Writeln("Level " & i)
Next i
' This is a way to stop list formatting.
builder.ListFormat.List = Nothing
builder.Document.Save(MyDir & "Lists.SpecifyListLevel Out.doc")Shows how to restart numbering in a list by copying a list.
[C#]
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(MyDir + "Lists.RestartNumberingUsingListCopy Out.doc");[Visual Basic]
Dim doc As Document = New Document()
Dim builder As DocumentBuilder = New DocumentBuilder(doc)
' Create a list based on a template.
Dim list1 As List = 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.
Dim list2 As List = 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(MyDir & "Lists.RestartNumberingUsingListCopy Out.doc")See Also
ListCollection Class | Aspose.Words.Lists Namespace | ListCollection.Add Overload List