Split a Table in Word Document into Two Tables with Keeping Numbered List Styles in Rows (Java) | Numbering Formats

Hello,

Is there a way to split a table in this way to keep the applied styles and so that adding a row in the first part of the table directly affects the second part of the table? I would be interested in the method presented below:

        Document doc = new Document();
        final DocumentBuilder documentBuilder = new DocumentBuilder(doc);
        final Table table = documentBuilder.startTable();
        /* create some columns and rows */
        // table.splitAfterRow(3); <----
        documentBuilder.endTable()

In the attachment, I am sending you a sample document. When you add a row in the first part of the table, the numbering of the second part automatically changes.
expected_table_behavior.zip (12.7 KB)

@aolo23,

You just need to make those Paragraphs in multiple Tables part of same List in Word document.

Document doc = new Document("C:\\Temp\\expected_table_behavior\\expected_table_behavior.docx");

// Simulate splitting a Table into Two
Table table = doc.getFirstSection().getBody().getTables().get(1);
Table cloned = (Table) doc.getFirstSection().getBody().getTables().get(1).deepClone(true);
table.getParentNode().insertAfter(new Paragraph(doc), table);
table.getParentNode().insertAfter(cloned, table.getNextSibling());
table.getLastRow().remove();
cloned.getLastRow().remove();
cloned.getLastRow().remove();

for (Paragraph para : (Iterable<Paragraph>) cloned.getChildNodes(NodeType.PARAGRAPH, true))
    if (para.isListItem() && para.getListFormat().getList().getListId() == 2)
        para.getListFormat().setList(doc.getLists().get(0));

doc.save("C:\\Temp\\expected_table_behavior\\21.2.docx");