Hi,
First of all, I’m using Aspose.Words 16.1.
I’m trying to merge a nested table into its parent one. But for some reasons, I can’t get the merged cells to fit correctly.
Please find below the code to reproduce with the attached documents:
public static void mergeTableRepro() throws Exception {
Document document = new Document("nested tables.docx");
NodeCollection<?> tables = document.getChildNodes(NodeType.TABLE, true);
Table fromTable = (Table) tables.get(1);
Table toTable = (Table) tables.get(0);
Row toRow = toTable.getFirstRow();
toRow.getLastCell().remove();
Cell firstCellFromTable = fromTable.getFirstRow().getFirstCell();
firstCellFromTable.getCellFormat().setPreferredWidth(PreferredWidth.fromPercent(16.7));
toRow.appendChild(firstCellFromTable);
Cell secondCellFromTable = fromTable.getFirstRow().getFirstCell();
secondCellFromTable.getCellFormat().setPreferredWidth(PreferredWidth.fromPercent(16.7));
toRow.appendChild(secondCellFromTable);
document.save("merged tables.docx");
}
Thanks for your help.
Best regards,