【问题标题】:How to get the row height in Excel?如何在Excel中获取行高?
【发布时间】:2020-05-11 14:34:43
【问题描述】:

有没有办法在openxml中获取excel行的行高? 就我而言,我使用 openxml 2.0 从 .net 数据表生成 excel 表。对于每个数据表行,我在 excel 中定义新行

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

之后我将单元格附加到行

 row.InsertBefore(newCell, refCell);

当完成生成 excel 表时,我想让每行高度增加它。但是使用时总是为空

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

请帮帮我!谢谢!

【问题讨论】:

    标签: excel openxml openxml-sdk


    【解决方案1】:

    Microsoft Excel Open XML Format 行只有在 customHeight 属性在 XML 中设置为 true 时才具有 height 属性,否则行高只是 DefaultRowHeight

    您应该首先检查row.CustomHeight != null && row.CustomHeight.Value == true 是否具有自定义高度,并且Height 属性不会为空。

    在另一种情况下,您可以在SheetFormatProperties.DefaultRowHeight 中获取默认行高。

    所以要将行高设置为您的自定义值,您需要将其CustomHeight 属性更改为true,并将Height 属性更改为您的自定义行高。

    【讨论】:

    • 感谢 Alexander Derck,我有带有文本值的单元格。将单元格(带值)插入单元格后,我如何获得行的行高?因为将单元格添加到行后,openxml会根据单元格中的字符数自动设置行高?
    • @TruongPham 还是一样。 Defaultrowheight 除非您为该行设置自定义行高。单元格不会变高,因为内容不合适
    猜你喜欢
    • 1970-01-01
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多