Free Support Forum - aspose.com

Wrong list item numbering when an item contains a table

Hi,

Creating a numbered list by using “builder.getListFormat().applyNumberDefault();” works fine if the table items contain simple text or pictures. However, when an item contains a table the table cells are numbered as well and the number of next list item is the number of the list item before (i.e. the list item that contains the table) plus the number of table cells. The attached PDF shows an example of the issue.
Do you know any possibility to circumvent that? Perhaps by creating lists in a different way?

Btw. The table is simply created with “builder.startTable();”.

Thank you so much for your help.

Regards,
Sebastian

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Please try using the following code:

Document doc = new Document();

// Create a list based on one of the Microsoft Word list templates.

List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);

DocumentBuilder builder = new DocumentBuilder(doc);

// Start list

builder.getListFormat().setList(list);

builder.writeln("List item one");

// Stop list

builder.getListFormat().removeNumbers();

//Build table

Table tab = builder.startTable();

for (int i = 0; i < 2; i++)

{

for (int j = 0; j < 2; j++)

{

builder.insertCell();

//Insert some value

builder.write("Table Cell");

}

builder.endRow();

}

builder.endTable();

// Continue list

builder.getListFormat().setList(list);

builder.writeln("List item two");

builder.writeln("List item three");

builder.getListFormat().removeNumbers();

// Save ouput document.

doc.save("C:\\Temp\\out.doc");

Best regards,

Hi,

thanks a lot for your fast response. Unfortunately, the listing doesn’t solve the issue because the table is not a part of the list (since builder.getListFormat().removeNumbers(); is called). The list item should contain the table. Is that possible with Apose Word?

Thanks again for your help!

Best regards,
Sebastian

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Table cannot be a part of list item. List item in MS Word documents is a single paragraph. But Paragraph node cannot contain Table node as a child. These nodes are on the same level in document’s nodes hierarchy. Please see the following link for more information:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/object-model-overview.html

Even in MS Word you cannot insert table inside list item (paragraph).

Best regards.