Free Support Forum - aspose.com

Cell merge not working properly

Team,


I am using Aspose for document conversion. I am trying to merge a table as show in attached image(expectedTable.jpg) .

Code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.startTable();

builder.insertCell().getCellFormat().setPreferredWidth(PreferredWidth.fromPoints(unitConversion(“2.1in”)));
builder.insertCell().getCellFormat().setPreferredWidth(PreferredWidth.fromPoints(unitConversion(“2.1in”)));
builder.insertCell().getCellFormat().setPreferredWidth(PreferredWidth.fromPoints(unitConversion(“2.1in”)));
builder.endRow(); //End Row 1

builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPoints(unitConversion(“4.2in”)));
builder.getCellFormat().setHorizontalMerge(CellMerge.FIRST);

builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPoints(0));
builder.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);

builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.NONE);
builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPoints(unitConversion(“2.1in”)));
builder.writeln(“23”);
builder.endRow(); // End Row2

builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPoints(unitConversion(“2.1in”)));
builder.writeln(“31”);

builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPoints(unitConversion(“4.2in”)));
builder.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
builder.writeln(“32”);

builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPoints(0));
builder.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
builder.writeln(“33”);
	builder.endRow();// End Row3 </i></font></div><div><font size="2" color="#808080"><i><br></i></font></div><div><font size="2" color="#808080"><i><br></i></font></div><div><font size="2" color="#808080"><i>builder.endTable();
	
	doc.save("out.docx", SaveFormat.DOCX);</i></font></div><div><br></div><div>After conversion, the output table is corrupted ( attached image : afterConversion.jpg )</div><div><br></div><div><i><span style="background-color: rgb(255, 255, 0);">But if i save the document as DOC( <b>SaveFormat.DOC ) </b>format, it is converted as expected.</span></i></div><div><i><span style="background-color: rgb(255, 255, 0);"><br></span></i></div><div><i><span style="background-color: rgb(255, 255, 0);"> It is not working in case of DOCX ( <b>SaveFormat.DOCX </b>) conversion.</span> </i></div><div><i><br></i></div><div><i>help me to solve this problem</i></div><div> </div><div>Regards,</div><div>Anbu S</div><div><br></div>
Hi Anbu,

Thanks for your inquiry. Perhaps, you're using an older version of Aspose.Words; as with Aspose.Words v11.10.0, I am unable to reproduce this problem on my side. I would suggest you please upgrade to the latest version of Aspose.Words i.e. v11.10.0 and let us know how it goes on your side. I hope, this will help.