Home » excel » openxml – How to get the row height in Excel?

openxml – How to get the row height in Excel?

Posted by: admin April 23, 2020 Leave a comment


Is there any way to get row height of excel row in openxml?
In my case, i use openxml 2.0 to generate excel table from .net datatable. For each datatable row, i define new row in excel by

  row = new Row() { RowIndex = rowIndex };

after that i append cell to row

 row.InsertBefore(newCell, refCell);

when finish generate excel table i want to get each row height to increase its. But it always null when use

    Row row = ExcelHelper.GetRow(sheetData, Convert.ToUInt32(13));
    DoubleValue a = row.Height;

Help me please! Thank!

How to&Answers:

Excel rows only have the Height attribute when there is a customheight (otherwise it’s just the DefaultRowHeight). What you should do is first check if row.CustomHeight == true and then you know it has a customheight and the row.Height value won’t be null.

In the other case you can check the customrowheight in the SheetFormatProperties.DefaultRowHeight.

So to set the height to another value of a row, you will need to change both CustomHeight and Height properties of the row.