Same list level - different font size in list labels

I am trying to create a list which contains different list labels (in terms of the font size / name).

Each time I apply to ListLabel font properties, last applied properties are taken for all other list labels.
I have tried to change ListFormat / ListLabel font properties but the result is the same.

How to achieve different labels as provided in the example below (zip file contains docx with the list I want to achieve)

List_example.zip (10.2 KB)

@drizgelis

Please check the following code example. Hope this helps you.

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.Font.Name = "Calibri";
builder.Font.Size = 24;
builder.Writeln("Item 2");
builder.ListFormat.RemoveNumbers();
builder.Font.ClearFormatting();
List list2 = doc.Lists.AddCopy(list1);

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(MyDir + "output.docx");

Thanks for this example.
I have seen this today but it’s not that intuitive when it comes with bigger lists.

Is this method of copying the list is the only way to achieve this result?
How to behave when it comes to the sub-lists?
Adding an example below.

Sub_items_added_example.zip (10.4 KB)

@drizgelis

You do not need to copy the list. The code example in my previous post show how to work with lists.

You can use following code example to achieve your requirement as shown in your shared document.

Moreover, the list items are paragraph nodes and you can format the paragraphs after creating the list according to your requirement. Please read the following articles.
Working with Paragraphs
Working with Lists

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Font.Name = "Calibri";
builder.Font.Size = 12;
// 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("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.Font.Size = 20;
builder.Writeln("PDF");
builder.Font.Size = 12;
builder.Writeln("HTML");

// Outdent to the first list level
builder.ListFormat.ListOutdent();
builder.Font.Size = 20;
builder.Writeln("Processing documents");
builder.Font.Size = 12;
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();

doc.Save(MyDir + "output.docx");

@tahir.manzoor

The main issue which I am getting is that I cannot have different list labels at the same level of the same list.

In my document, provided above (Sub_items_added_example.zip), I have attached an example where I have created the list with different labels, but it is seen as the same list in MS Word.

When I am trying to do that in Aspose Words, last applied list label font is applied to all same level items.

I have achieved my possible result by creating a list copy and setting startAt based on my context, which is calculated internally, but this solution is clumsy.

@drizgelis

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior. If Sub_items_added_example.docx is your expected output, please do not share it.
  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.