List Class

Represents formatting of a list.

Inheritance Hierarchy

SystemObject
  Aspose.Words.ListsList

Namespace:  Aspose.Words.Lists
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.7.0

Syntax

public class List : IComparable<List>

The List type exposes the following members.

Properties

  NameDescription
Public propertyCode exampleDocument
Gets the owner document.
Public propertyCode exampleIsListStyleDefinition
Returns true if this list is a definition of a list style.
Public propertyCode exampleIsListStyleReference
Returns true if this list is a reference to a list style.
Public propertyCode exampleIsMultiLevel
Returns true when the list contains 9 levels; false when 1 level.
Public propertyCode exampleIsRestartAtEachSection
Specifies whether list should be restarted at each section. Default value is false.
Public propertyCode exampleListId
Gets the unique identifier of the list.
Public propertyCode exampleListLevels
Gets the collection of list levels for this list.
Public propertyCode exampleStyle
Gets the list style that this list references or defines.

Methods

  NameDescription
Public methodCompareTo(Object)
Compares the specified object to the current object.
Public methodCompareTo(List)
Compares the specified list to the current list.
Public methodEquals(Object) (Overrides ObjectEquals(Object).)
Public methodEquals(List)
Compares with the specified list.
Public methodGetHashCode
Calculates hash code for this list object.
(Overrides ObjectGetHashCode.)
Public methodGetType (Inherited from Object.)
Public methodToString (Inherited from Object.)

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.

Examples

Shows how to specify list level number when building a list using DocumentBuilder.
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);

// Insert text at each of the 9 indent levels
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);

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;

doc.Save(ArtifactsDir + "Lists.SpecifyListLevel.docx");
Shows how to restart numbering in a list by copying a list.
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();

doc.Save(ArtifactsDir + "Lists.RestartNumberingUsingListCopy.docx");
Shows how to apply custom list formatting to paragraphs when using DocumentBuilder.
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 listLevel = list.ListLevels[0];
listLevel.Font.Color = Color.Red;
listLevel.Font.Size = 24;
listLevel.NumberStyle = NumberStyle.OrdinalText;
listLevel.StartAt = 21;
listLevel.NumberFormat = "\x0000";

listLevel.NumberPosition = -36;
listLevel.TextPosition = 144;
listLevel.TabPosition = 144;

// Customize another list level
listLevel = list.ListLevels[1];
listLevel.Alignment = ListLevelAlignment.Right;
listLevel.NumberStyle = NumberStyle.Bullet;
listLevel.Font.Name = "Wingdings";
listLevel.Font.Color = Color.Blue;
listLevel.Font.Size = 24;
listLevel.NumberFormat = "\xf0af"; // A bullet that looks like a star
listLevel.TrailingCharacter = ListTrailingCharacter.Space;
listLevel.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(ArtifactsDir + "Lists.CreateCustomList.docx");

See Also