Free Support Forum - aspose.com

I want to get Table.cell height or vertically spanning several cell count

I want to get Table.cell height or vertically spanning several cell count
How do I operate? Thanks!
image.png (7.1 KB)

3.png (12.6 KB)
2.png (56.4 KB)

@RyanSheng,

Thanks for your inquiry. To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

Your simplified input Word document
Your expected Cell height value that you would like Aspose.Words to return for a particular vertically merged Cell.

As soon as you get these pieces of information ready, we will start further investigation into your issue and provide you more information. Thanks for your cooperation.

test.zip (11.5 KB)

@RyanSheng,

Please try using the following code:

Document doc = new Document("D:\\test\\test.docx");

Table tab = doc.FirstSection.Body.Tables[0];
double totalHeight = 0;
foreach (Row row in tab.Rows)
{
    totalHeight += row.RowFormat.Height;
}

Console.WriteLine("height in inches = " + totalHeight/72);

I want to know the height of the cells when the cells are merged.

I want to know the height after merging cells. For example, there are 6 vertically merged cells in a .doc file. How do I get “6” value from the code? thanks

@RyanSheng,

We are working on your query and will get back to you soon

@RyanSheng,

The following code prints the horizontal and vertical merge type of a cell. I think, you can build on this logic to meet this requirement.

public static string PrintCellMergeType(Cell cell)
{
    bool isHorizontallyMerged = cell.CellFormat.HorizontalMerge != CellMerge.None;
    bool isVerticallyMerged = cell.CellFormat.VerticalMerge != CellMerge.None;
    string cellLocation = string.Format("R{0}, C{1}", cell.ParentRow.ParentTable.IndexOf(cell.ParentRow) + 1, cell.ParentRow.IndexOf(cell) + 1);

    if (isHorizontallyMerged && isVerticallyMerged)
        return string.Format("The cell at {0} is both horizontally and vertically merged", cellLocation);
    else if (isHorizontallyMerged)
        return string.Format("The cell at {0} is horizontally merged.", cellLocation);
    else if (isVerticallyMerged)
        return string.Format("The cell at {0} is vertically merged", cellLocation);
    else
        return string.Format("The cell at {0} is not merged", cellLocation);
}
///////////////////////////
Document doc = new Document("D:\\temp\\test\\test.docx");

Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

foreach (Row row in table.Rows)
{
    foreach (Cell cell in row.Cells)
    {
        Console.WriteLine(PrintCellMergeType(cell));
    }
}