Free Support Forum - aspose.com

Problem with drowing table with merged cells

Hi guys!
I have a problem with drowing table using Aspose.Words

So I need to get this result table:
-link to proper table view -


To drow this table I've written the next code:

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

Table table = builder.startTable();

builder.insertCell();
builder.write(“ROW 1”);

builder.insertCell();
builder.getCellFormat().setHorisontalMerge(CellMerge.FIRST);
builder.write(“VALUE 1”);

builder.insertCell();
builder.getCellFormat().setHorisontalMerge(CellMerge.PREVIOUS);

builder.insertCell();
builder.getCellFormat().setHorisontalMerge(CellMerge.PREVIOUS);

builder.endRow();

// next row
builder.insertCell();
builder.write(“ROW 2”);

builder.insertCell();
builder.write(“VLAUE 2_1”);

builder.insertCell();
builder.write(“VLAUE 2_2”);

builder.insertCell();
builder.write(“VLAUE 2_3”);

builder.endRow();
builder.endTable()

But as usually in reality… I’m getting next table:
- link to incorrect table view-

My question is why cell ‘VALUE 1’ doesn’t cover all “VALUE 2_*” cells from “ROW 2”, why does it cover only one cell “VALUE 2_1”?
And how can I drow prpoper table from my example?



Hi Eugene,


Thanks for your inquiry. First off, please upgrade to the latest version of Aspose.Words for Java i.e. 15.6.0.
http://www.aspose.com/community/files/72/java-components/aspose.words-for-java/default.aspx

Secondly, I have fixed your code as follows:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = builder.startTable();

builder.insertCell();
builder.write(“ROW 1”);

builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
builder.write(“VALUE 1”);

builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);

builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);

builder.endRow();

// next row
builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.NONE);
builder.write(“ROW 2”);

builder.insertCell();
builder.write(“VLAUE 2_1”);

builder.insertCell();
builder.write(“VLAUE 2_2”);

builder.insertCell();
builder.write(“VLAUE 2_3”);

builder.endRow();
builder.endTable();

doc.save(getMyDir() + “15.6.0.docx”);

I hope, this helps.

Best regards,