4

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!

Alexander Derck
  • 13,818
  • 5
  • 54
  • 76
Truong Pham
  • 41
  • 1
  • 3

1 Answers1

2

The Microsoft Excel Open XML Format rows only have the height attribute when customHeight attribute is set to true in XML, otherwise the row height is just the DefaultRowHeight.

What you should do is first check if row.CustomHeight != null && row.CustomHeight.Value == true and then you know it has a custom height and the Height property won't be null.

In the other case you can get the default row height in the SheetFormatProperties.DefaultRowHeight.

So to set the height of a row to your custom value, you need to change its CustomHeight property to true, and Height property to your custom row height.

Alexander Derck
  • 13,818
  • 5
  • 54
  • 76
  • Thank Alexander Derck, i have cell with text value. After insert cell (with value) to cell, how could i get rowheight of row? Because after add cell to row, openxml will automatically set rowheight base on number of character in cell? – Truong Pham Jan 14 '16 at 00:59
  • @TruongPham Still the same. Defaultrowheight unless you set a custom row height for the row. Cells don't get higher because the content doesn't fit – Alexander Derck Jan 14 '16 at 07:31