How to create a bullet list w/ sub bullets

I’ve created a simple bullet list using the document builder. Now I want to add sub bullets to some of the bullet items with the indent increased. However I am unable to get this working. I have tried specifying variations with the TabPosition, NumberPosition, and calling ListIndent method. Is there an example of how to do this someplace? I haven’t found anything and the documentation on this is unclear to me.

Thanks!

Hi Shane,

Thanks for your inquiry. Please use the ListFormat.ListIndent method to increase the list level of the current paragraph by one level. This method changes the list level and applies formatting properties of the new level.

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.

Use the ListFormat.ListOutdent Method to decrease the list level of the current paragraph by one level.

Please use the following code example to achieve your requirments. Hope this helps you. If you still face problem, please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate, how you want your final Word output be generated like. We will then provide you more information on this along with code.

DocumentBuilder builder = new DocumentBuilder();
builder.Writeln("Aspose.Words allows:");
builder.Writeln();
// Start a numbered list with default formatting.
builder.ListFormat.ApplyNumberDefault();
builder.Writeln("Opening documents from different formats:");
// Go to second list level, add more text.
builder.ListFormat.ListIndent();
builder.Writeln("DOC");
builder.Writeln("PDF");
builder.Writeln("HTML");
// Outdent to the first list level.
builder.ListFormat.ListOutdent();
builder.Writeln("Processing documents");
builder.Writeln("Saving documents in different formats:");
// Indent the list level again.
builder.ListFormat.ListIndent();
builder.Writeln("DOC");
builder.Writeln("PDF");
builder.Writeln("HTML");
builder.Writeln("MHTML");
builder.Writeln("Plain text");
// Outdent the list level again.
builder.ListFormat.ListOutdent();
builder.Writeln("Doing many other things!");
// End the numbered list.
builder.ListFormat.RemoveNumbers();
builder.Writeln();
builder.Writeln("Aspose.Words main advantages are:");
builder.Writeln();
// Start a bulleted list with default formatting.
builder.ListFormat.ApplyBulletDefault();
builder.Writeln("Great performance");
builder.Writeln("High reliability");
builder.Writeln("Quality code and working");
builder.Writeln("Wide variety of features");
builder.Writeln("Easy to understand API");
// End the bulleted list.
builder.ListFormat.RemoveNumbers();
builder.Document.Save(MyDir + "Lists.ApplyDefaultBulletsAndNumbers Out.doc");

Moreover, please note that 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.

Following code example shows how to specify list level number when building a list using DocumentBuilder. Hope this helps you.

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");

Thank you for the very thorough answer. This is exactly what I needed.

Hi Shane,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.