Aspose.Words allows the easy creation of lists by applying list formatting. DocumentBuilder provides the ListFormat property that returns a ListFormat object. This object has several methods to start and end a list and to increase/decrease the indent.
There are two general types of lists in Microsoft Word: bulleted and numbered.
- To start a bulleted list, call ListFormat.ApplyBulletDefault.
- To start a numbered list, call ListFormat.ApplyNumberDefault.
The bullet or number and formatting are added to the current paragraph and all further paragraphs created using DocumentBuilder until ListFormat.RemoveNumbers is called to stop bulleted list formatting.
In Word documents, lists may consist of up to nine levels. List formatting for each level specifies what bullet or number is used, left indent, space between the bullet and text etc.
- To increase the list level of the current paragraph by one level, call ListFormat.ListIndent.
- To decrease the list level of the current paragraph by one level, call ListFormat.ListOutdent.
The methods change the list level and apply the formatting properties of the new level.
You can also use the ListFormat.ListLevelNumber property to get or set the list level for the paragraph. The list levels are numbered 0 to 8.
Example DocumentBuilderSetListFormatting
Shows how to build a multilevel list.
[C#]
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.ListFormat.ApplyNumberDefault();
builder.Writeln("Item 1");
builder.Writeln("Item 2");
builder.ListFormat.ListIndent();
builder.Writeln("Item 2.1");
builder.Writeln("Item 2.2");
builder.ListFormat.ListIndent();
builder.Writeln("Item 2.2.1");
builder.Writeln("Item 2.2.2");
builder.ListFormat.ListOutdent();
builder.Writeln("Item 2.3");
builder.ListFormat.ListOutdent();
builder.Writeln("Item 3");
builder.ListFormat.RemoveNumbers();
[Visual Basic]
Dim doc As Document = New Document()
Dim builder As DocumentBuilder = New DocumentBuilder(doc)
builder.ListFormat.ApplyNumberDefault()
builder.Writeln("Item 1")
builder.Writeln("Item 2")
builder.ListFormat.ListIndent()
builder.Writeln("Item 2.1")
builder.Writeln("Item 2.2")
builder.ListFormat.ListIndent()
builder.Writeln("Item 2.2.1")
builder.Writeln("Item 2.2.2")
builder.ListFormat.ListOutdent()
builder.Writeln("Item 2.3")
builder.ListFormat.ListOutdent()
builder.Writeln("Item 3")
builder.ListFormat.RemoveNumbers()
[Java]
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getListFormat().applyNumberDefault();
builder.writeln("Item 1");
builder.writeln("Item 2");
builder.getListFormat().listIndent();
builder.writeln("Item 2.1");
builder.writeln("Item 2.2");
builder.getListFormat().listIndent();
builder.writeln("Item 2.2.1");
builder.writeln("Item 2.2.2");
builder.getListFormat().listOutdent();
builder.writeln("Item 2.3");
builder.getListFormat().listOutdent();
builder.writeln("Item 3");
builder.getListFormat().removeNumbers();