【问题标题】:EPPlus formatting value from formula公式中的 EPPlus 格式化值
【发布时间】:2015-11-21 14:21:55
【问题描述】:

我有一个用 EPPlus 生成的 Excel 电子表格。最后一列使用公式包含整行的总计。

ws.Cells[rowIndex, colIndex].Formula = formulaString.ToString().Substring(0, formulaString.Length - 1);

我在分配公式后使用Calculate()方法:

ws.Cells[rowIndex, colIndex].Calculate();

然后就是用这个来格式化单元格:

ws.Cells[rowIndex, colIndex].Style.Numberformat.Format = "### ### ### ###";

公式是正确的,但是当我设置单元格的样式时,如果单元格的值为 0,它只会使其空白。如果单元格的值大于 0,则其样式完美。

有人遇到过这个问题吗?

【问题讨论】:

    标签: c# epplus


    【解决方案1】:

    这几乎就是它应该做的。 # 基本上意味着它是一个可选数字,并且什么都不显示它不存在或 0。这是一个 excel 的东西,而不是真正的 epplus。

    我想你想要的是

    ws.Cells[rowIndex, colIndex].Style.Numberformat.Format = "### ### ### ##0";
    

    https://support.office.com/en-us/article/Create-or-delete-a-custom-number-format-83657ca7-9dbe-4ee5-9c89-d8bf836e028e?ui=en-US&rs=en-US&ad=US

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-26
      • 1970-01-01
      相关资源
      最近更新 更多