Represents formatting of a list.
For a list of all members of this type, see List Members.
System.Object
Aspose.Words.Lists.List
[Visual Basic]
Public Class List
Remarks
A list in a Microsoft Word document is a set of list formatting properties. Each list can have up to 9 levels and formatting properties, such as number style, start value, indent, tab position etc are defined separately for each level.
A List object always belongs to the ListCollection collection.
To create a new list, use the Add methods of the ListCollection collection.
To modify formatting of a list, use ListLevel objects found in the ListLevels collection.
To apply or remove list formatting from a paragraph, use ListFormat.
Example
Shows 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")Shows how to apply custom list formatting to paragraphs when using DocumentBuilder.
[C#]
Document doc = new Document();
// Create a list based on one of the Microsoft Word list templates.
List list = doc.Lists.Add(ListTemplate.NumberDefault);
// Completely customize one list level.
ListLevel level1 = list.ListLevels[0];
level1.Font.Color = Color.Red;
level1.Font.Size = 24;
level1.NumberStyle = NumberStyle.OrdinalText;
level1.StartAt = 21;
level1.NumberFormat = "\x0000";
level1.NumberPosition = -36;
level1.TextPosition = 144;
level1.TabPosition = 144;
// Completely customize yet another list level.
ListLevel level2 = list.ListLevels[1];
level2.Alignment = ListLevelAlignment.Right;
level2.NumberStyle = NumberStyle.Bullet;
level2.Font.Name = "Wingdings";
level2.Font.Color = Color.Blue;
level2.Font.Size = 24;
level2.NumberFormat = "\xf0af"; // A bullet that looks like some sort of a star.
level2.TrailingCharacter = ListTrailingCharacter.Space;
level2.NumberPosition = 144;
// Now add some text that uses the list that we created.
// It does not matter when to customize the list - before or after adding the paragraphs.
DocumentBuilder builder = new DocumentBuilder(doc);
builder.ListFormat.List = list;
builder.Writeln("The quick brown fox...");
builder.Writeln("The quick brown fox...");
builder.ListFormat.ListIndent();
builder.Writeln("jumped over the lazy dog.");
builder.Writeln("jumped over the lazy dog.");
builder.ListFormat.ListOutdent();
builder.Writeln("The quick brown fox...");
builder.ListFormat.RemoveNumbers();
builder.Document.Save(MyDir + "Lists.CreateCustomList Out.doc");[Visual Basic]
Dim doc As Document = New Document()
' Create a list based on one of the Microsoft Word list templates.
Dim list As List = doc.Lists.Add(ListTemplate.NumberDefault)
' Completely customize one list level.
Dim level1 As ListLevel = list.ListLevels(0)
level1.Font.Color = Color.Red
level1.Font.Size = 24
level1.NumberStyle = NumberStyle.OrdinalText
level1.StartAt = 21
level1.NumberFormat = "\x0000"
level1.NumberPosition = -36
level1.TextPosition = 144
level1.TabPosition = 144
' Completely customize yet another list level.
Dim level2 As ListLevel = list.ListLevels(1)
level2.Alignment = ListLevelAlignment.Right
level2.NumberStyle = NumberStyle.Bullet
level2.Font.Name = "Wingdings"
level2.Font.Color = Color.Blue
level2.Font.Size = 24
level2.NumberFormat = "\xf0af" ' A bullet that looks like some sort of a star.
level2.TrailingCharacter = ListTrailingCharacter.Space
level2.NumberPosition = 144
' Now add some text that uses the list that we created.
' It does not matter when to customize the list - before or after adding the paragraphs.
Dim builder As DocumentBuilder = New DocumentBuilder(doc)
builder.ListFormat.List = list
builder.Writeln("The quick brown fox...")
builder.Writeln("The quick brown fox...")
builder.ListFormat.ListIndent()
builder.Writeln("jumped over the lazy dog.")
builder.Writeln("jumped over the lazy dog.")
builder.ListFormat.ListOutdent()
builder.Writeln("The quick brown fox...")
builder.ListFormat.RemoveNumbers()
builder.Document.Save(MyDir & "Lists.CreateCustomList Out.doc")Requirements
Namespace: Aspose.Words.Lists
Assembly: Aspose.Words (in Aspose.Words.dll)
See Also
List Members | Aspose.Words.Lists Namespace | ListCollection | ListLevel | ListFormat