A collection of list formatting for each level in a list.
For a list of all members of this type, see ListLevelCollection Members.
System.Object
Aspose.Words.Lists.ListLevelCollection
[Visual Basic]Public Class ListLevelCollection
Example
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")Shows how to create a list style and use it in a document.
[C#]
Document doc = new Document();
// Create a new list style.
// List formatting associated with this list style is default numbered.
Style listStyle = doc.Styles.Add(StyleType.List, "MyListStyle");
// This list defines the formatting of the list style.
// Note this list can not be used directly to apply formatting to paragraphs (see below).
List list1 = listStyle.List;
// Check some basic rules about the list that defines a list style.
Assert.AreEqual(true, list1.IsListStyleDefinition);
Assert.AreEqual(false, list1.IsListStyleReference);
Assert.AreEqual(true, list1.IsMultiLevel);
Assert.AreEqual(listStyle, list1.Style);
// Modify formatting of the list style to our liking.
for (int i = 0; i < list1.ListLevels.Count; i++)
{
ListLevel level = list1.ListLevels[i];
level.Font.Name = "Verdana";
level.Font.Color = Color.Blue;
level.Font.Bold = true;
}
// Add some text to our document and use the list style.
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Using list style first time:");
// This creates a list based on the list style.
List list2 = doc.Lists.Add(listStyle);
// Check some basic rules about the list that references a list style.
Assert.AreEqual(false, list2.IsListStyleDefinition);
Assert.AreEqual(true, list2.IsListStyleReference);
Assert.AreEqual(listStyle, list2.Style);
// Apply the list that references the list style.
builder.ListFormat.List = list2;
builder.Writeln("Item 1");
builder.Writeln("Item 2");
builder.ListFormat.RemoveNumbers();
builder.Writeln("Using list style second time:");
// Create and apply another list based on the list style.
List list3 = doc.Lists.Add(listStyle);
builder.ListFormat.List = list3;
builder.Writeln("Item 1");
builder.Writeln("Item 2");
builder.ListFormat.RemoveNumbers();
builder.Document.Save(MyDir + "Lists.CreateAndUseListStyle Out.doc");[Visual Basic]
Dim doc As Document = New Document()
' Create a new list style.
' List formatting associated with this list style is default numbered.
Dim listStyle As Style = doc.Styles.Add(StyleType.List, "MyListStyle")
' This list defines the formatting of the list style.
' Note this list can not be used directly to apply formatting to paragraphs (see below).
Dim list1 As List = listStyle.List
' Check some basic rules about the list that defines a list style.
Assert.AreEqual(True, list1.IsListStyleDefinition)
Assert.AreEqual(False, list1.IsListStyleReference)
Assert.AreEqual(True, list1.IsMultiLevel)
Assert.AreEqual(listStyle, list1.Style)
' Modify formatting of the list style to our liking.
Dim i As Integer = 0
Do While i < list1.ListLevels.Count
Dim level As ListLevel = list1.ListLevels(i)
level.Font.Name = "Verdana"
level.Font.Color = Color.Blue
level.Font.Bold = True
i += 1
Loop
' Add some text to our document and use the list style.
Dim builder As DocumentBuilder = New DocumentBuilder(doc)
builder.Writeln("Using list style first time:")
' This creates a list based on the list style.
Dim list2 As List = doc.Lists.Add(listStyle)
' Check some basic rules about the list that references a list style.
Assert.AreEqual(False, list2.IsListStyleDefinition)
Assert.AreEqual(True, list2.IsListStyleReference)
Assert.AreEqual(listStyle, list2.Style)
' Apply the list that references the list style.
builder.ListFormat.List = list2
builder.Writeln("Item 1")
builder.Writeln("Item 2")
builder.ListFormat.RemoveNumbers()
builder.Writeln("Using list style second time:")
' Create and apply another list based on the list style.
Dim list3 As List = doc.Lists.Add(listStyle)
builder.ListFormat.List = list3
builder.Writeln("Item 1")
builder.Writeln("Item 2")
builder.ListFormat.RemoveNumbers()
builder.Document.Save(MyDir & "Lists.CreateAndUseListStyle Out.doc")Requirements
Namespace: Aspose.Words.Lists
Assembly: Aspose.Words (in Aspose.Words.dll)
See Also
ListLevelCollection Members | Aspose.Words.Lists Namespace