We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose Words for Java - table cell merge not working properly

Hi,

I want to make a table header with both horizontal and vertical merged cells in Java, just like attached screenshot, but the following codes don’t work - the right part of the result table header is messy and incorrect:

setStyle(builder, Color.WHITE, FONT_SIZE_TEXT, true, ParagraphAlignment.CENTER);
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.FIRST);
builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
builder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.getCellFormat().getBorders().setColor(Color.GRAY);
builder.getCellFormat().getShading().setBackgroundPatternColor(COLOR_BLUE);
builder.getCellFormat().setWidth(80);
builder.write(“Individual Goals”);

setStyle(builder, Color.WHITE, FONT_SIZE_TEXT, true, ParagraphAlignment.CENTER);
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.FIRST);
builder.getCellFormat().getShading().setBackgroundPatternColor(COLOR_BLUE);
builder.getCellFormat().setWidth(160);
builder.write(“Measures”);

setStyle(builder, Color.WHITE, FONT_SIZE_TEXT, true, ParagraphAlignment.CENTER);
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.FIRST);
builder.getCellFormat().getShading().setBackgroundPatternColor(COLOR_BLUE);
builder.getCellFormat().setWidth(40);
builder.write(“Weighting”);

setStyle(builder, Color.WHITE, FONT_SIZE_TEXT, true, ParagraphAlignment.CENTER);
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
builder.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
builder.getCellFormat().getShading().setBackgroundPatternColor(COLOR_BLUE);
builder.getCellFormat().setWidth(120);
builder.write(“Targets”);

// This cell is merged to the previous and should be empty.
builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
builder.getCellFormat().setWidth(0);

// This cell is merged to the previous and should be empty.
builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
builder.getCellFormat().setWidth(0);

setStyle(builder, Color.WHITE, FONT_SIZE_TEXT, true, ParagraphAlignment.CENTER);
builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.NONE);
builder.getCellFormat().setVerticalMerge(CellMerge.FIRST);
builder.getCellFormat().getShading().setBackgroundPatternColor(COLOR_BLUE);
builder.getCellFormat().setWidth(100);
builder.write(“Mid Year Review”);

setStyle(builder, Color.WHITE, FONT_SIZE_TEXT, true, ParagraphAlignment.CENTER);
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.FIRST);
builder.getCellFormat().getShading().setBackgroundPatternColor(COLOR_BLUE);
builder.getCellFormat().setWidth(100);
builder.write(“Final Review”);

setStyle(builder, Color.WHITE, FONT_SIZE_TEXT, true, ParagraphAlignment.CENTER);
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.FIRST);
builder.getCellFormat().getShading().setBackgroundPatternColor(COLOR_BLUE);
builder.getCellFormat().setWidth(200);
builder.write(“Comments”);

builder.endRow();

// This cell is vertically merged to the cell above and should be empty.
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.PREVIOUS);
builder.getCellFormat().setWidth(80);

// This cell is vertically merged to the cell above and should be empty.
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.PREVIOUS);
builder.getCellFormat().setWidth(160);

// This cell is vertically merged to the cell above and should be empty.
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.PREVIOUS);
builder.getCellFormat().setWidth(40);

setStyle(builder, Color.WHITE, FONT_SIZE_TEXT, true, ParagraphAlignment.CENTER);
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
builder.getCellFormat().getShading().setBackgroundPatternColor(COLOR_LIGHT_BLUE);
builder.getCellFormat().setWidth(40);
builder.write(“Threshold”);

setStyle(builder, Color.WHITE, FONT_SIZE_TEXT, true, ParagraphAlignment.CENTER);
builder.insertCell();
builder.getCellFormat().getShading().setBackgroundPatternColor(COLOR_LIGHT_BLUE);
builder.getCellFormat().setWidth(40);
builder.write(“Business Plan”);

setStyle(builder, Color.WHITE, FONT_SIZE_TEXT, true, ParagraphAlignment.CENTER);
builder.insertCell();
builder.getCellFormat().getShading().setBackgroundPatternColor(COLOR_LIGHT_BLUE);
builder.getCellFormat().setWidth(40);
builder.write(“Excellent”);

// This cell is vertically merged to the cell above and should be empty.
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.PREVIOUS);
builder.getCellFormat().getShading().setBackgroundPatternColor(COLOR_BLUE);
builder.getCellFormat().setWidth(0);

// This cell is vertically merged to the cell above and should be empty.
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.PREVIOUS);
builder.getCellFormat().getShading().setBackgroundPatternColor(COLOR_BLUE);
builder.getCellFormat().setWidth(0);

// This cell is vertically merged to the cell above and should be empty.
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.PREVIOUS);
builder.getCellFormat().getShading().setBackgroundPatternColor(COLOR_BLUE);
builder.getCellFormat().setWidth(0);

builder.endRow();

It took me a long time trying to fix the issue, but didn’t prevail. Could anyone help me?

Thanks very much.

Mark

I solved the issue accidentally by adding one more line as below before saving the document:

<span style=“font-size: 10pt; font-family: “Courier New”; background: none repeat scroll 0% 0% yellow;”>doc.UpdatePageLayout();

Thanks.

Hi

It is perfect that you managed to resolve the problem. Please let us know if you need more assistance, we will be glad to help you.

Best regards,

Hi Alexey,

This forum is helpful. I took some hint from another post, and solved the above issue.

Thanks a lot.

Mark

Hi Mark,

It is perfect that you managed to implement what you need. Please feel free to ask in case of any issues, we will be glad to help you.

Best regards,