When I am creating a document programmatically with aspose like below and then appending with another document the merge cells are not retained. Please see the below code reproduce. “SomePage.docx” can be any document.
private static void cellMergeTest() throws Exception {
Document firstDoc = new Document(new FileInputStream(new File(DATA_DIR+"SomePage.docx")));
new DocumentBuilder(firstDoc).write("This is the first page of the document");
Document tableDoc = new Document();
DocumentBuilder builder = new DocumentBuilder(tableDoc);
builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
builder.write("Text in merged cells.");
builder.insertCell();
// This cell is merged to the previous and should be empty.
builder.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
builder.endRow();
builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.NONE);
builder.write("Text in one cell.");
builder.insertCell();
builder.write("Text in another cell.");
builder.endRow();
builder.endTable();
tableDoc.save(OUT_DIR + "tableDoc.docx");
firstDoc.getFirstSection().getPageSetup().setSectionStart(SectionStart.NEW_PAGE);
firstDoc.appendDocument(tableDoc, ImportFormatMode.USE_DESTINATION_STYLES);
firstDoc.updatePageLayout();
firstDoc.updateTableLayout();
firstDoc.save(OUT_DIR+"mergedDoc.docx");
}