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

Free Support Forum - aspose.com

How to get vertically merged cell's correct size | Aspose words java api

I am using LayoutEnumerator to get the width and height of table cells. I also printed out the layout information of the cells.

I found that, for horizontally merged cells, aspose treated the merged cell as one cell. However, for vertically merged cells, aspose treated the merged cells as several cells (the number of cell before merge). What aspose does is to move all of the contents in all of cells to be merge to the first cell and keep all other cells as there. So when I call getRectangle() method on the merged cells, the result is wrong which gives me the height and weight of a single cell before merging.


To meet this requirement, you can simply get the height of first vertically merged cell:

Document doc = new Document("C:\\Temp\\vertical merge cells.docx");

LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);

Table table = doc.FirstSection.Body.Tables[0];

foreach (Cell cell in table.GetChildNodes(NodeType.Cell, true))
    if (cell.CellFormat.VerticalMerge == CellMerge.First)
        enumerator.Current = collector.GetEntity(cell.FirstParagraph);

        while (enumerator.MoveParent())
            if (enumerator.Type == LayoutEntityType.Cell)