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

Free Support Forum - aspose.com

CellFormat.HorizontalMerge reduces the cell's width using Java

Hello. We are trying to merge cells so that one cell spans the entire table. This works sometimes but sometimes the merged cell does not span the entire table width. Can you please tell us what we are doing wrong? Attached is merge-error.docx which contains the unmerged cells. Merge-error-result.docx contains the merged cells. The cells are merged incorrectly in the last two tables. The top two rows should span the entire table width, but they only span 3 cells. Here is the code we have used to merge the cells:

    Document document = new Document("merge-error.docx");
    for (Object node : document.getChildNodes(com.aspose.words.NodeType.TABLE, true)) {
        Table table = (Table)node;
        for (int i = 0; i < 2; i++) {
            Boolean first = true;
            for (Cell cell : table.getRows().get(i).getCells()) {
                if (first) {
                    cell.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
                    first = false;
                } else {
                    cell.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
                }
            }
        }
    }
    document.save("merge-error-result.docx");

documents.zip (32.1 KB)

@bmpi

Could you please ZIP and attach your expected output document here for our reference? We will then provide you more information about your query.

Here it is. In the last two tables, the top two rows each are merged horizontally so that it is one cell spanning the entire table width.
merge-error-expected.zip (14.2 KB)

@bmpi

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-18822. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Can you give us a rough estimate on when this is going to be fixed? I see the status is postponed?

@bmpi

We regret to share with you that the issue (WORDSNET-18822) has been postponed due to missing feature WORDSNET-832 ( Make table layout as close to Word as possible ) which is related to it.

After the fix of WORDSNET-832, we will look into this issue. We will be sure to inform you via this forum thread as soon as this feature is available. We apologize for your inconvenience.

Can you tell us the current status?

@bmpi

Unfortunately, there is no update available on this issue. You will be notified via this forum thread one this issue is resolved. We apologize for your inconvenience.