Rendering issue for table containing only staggered horizontally merged cells

Creating table via DocumentBuilder.
Aspose Words for Java 19.10
Output Attached

Reproduction code:

staggered-cells.docx.zip

	@Test
	public void testStaggeredHorizontalMerge() throws Exception {
		ClassLoader classLoader = getClass().getClassLoader();
		com.aspose.words.Document document = new com.aspose.words.Document();
		document.removeAllChildren();
		DocumentBuilder builder = new DocumentBuilder(document);
		builder.write("Table of 3 columns with rows containing staggered horizontal merges:");
		// Add a table with ONLY cells with staggered horizontal merge
		addStaggeredCells(builder);
		builder.endTable();
		builder.insertParagraph();
		builder.write ("Table with same rows but adding a row without any merged cells:");
		// Use same code to create same staggered horizontal merge
		// But then add a row containing only unmerged cells.
		addStaggeredCells(builder);
		builder.insertCell();
		builder.write ("10");
		builder.insertCell();
		builder.write ("11");
		builder.insertCell();
		builder.write ("12");
		builder.endRow();
		builder.endTable();
		builder.insertParagraph();
		builder.write ("I expect the first three rows of each table to render identically since they all contain 3 cells and are created with the same code.");
		document.save("staggered-cells.docx");
	}

	void addStaggeredCells (DocumentBuilder builder) {
		com.aspose.words.Table table = builder.startTable();
		Cell cell = builder.insertCell();
		cell.getCellFormat().setHorizontalMerge(CellMerge.NONE);
		builder.write ("1");
		cell = builder.insertCell();
		cell.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
		builder.write ("2");
		cell = builder.insertCell();
		cell.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
		builder.endRow();
		cell = builder.insertCell();
		cell.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
		builder.write ("4");
		cell = builder.insertCell();
		cell.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
		cell = builder.insertCell();
		cell.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
		builder.endRow();
		cell = builder.insertCell();
		cell.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
		builder.write ("7");
		cell = builder.insertCell();
		cell.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
		cell = builder.insertCell();
		cell.getCellFormat().setHorizontalMerge(CellMerge.NONE);
		builder.write ("9");
		builder.endRow();
	}

@neallester

We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-19449. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@neallester

Thanks for your patience. It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-19449) as ‘Not a Bug’.

You create table with auto fit behaviour (AllowAutoFit = true by default). So, when additional row was added then table grid were changed. So, please disable the “AutoFit” property to get similar result for previous rows when decided to add a new row.

Please use the following code example to get the desired output.

Document document = new Document();

DocumentBuilder builder = new DocumentBuilder(document);
builder.write("Table of 3 columns with rows containing staggered horizontal merges:");
// Add a table with ONLY cells with staggered horizontal merge
addStaggeredCells(builder);
Table tbl = builder.endTable();
tbl.setAllowAutoFit(false);

builder.insertParagraph();
builder.write("Table with same rows but adding a row without any merged cells:");
// Use same code to create same staggered horizontal merge
// But then add a row containing only unmerged cells.
addStaggeredCells(builder);
builder.insertCell();
builder.write("10");
builder.insertCell();
builder.write("11");
builder.insertCell();
builder.write("12");
builder.endRow();
tbl = builder.endTable();
tbl.setAllowAutoFit(false);

builder.insertParagraph();
document.save(MyDir + "19.11.docx");