首页 > 解决方案 > EPPlus SUMIFS 返回值 #VALUE

问题描述

我正在用 EPPlus 生成 excel 文件。最后,我尝试获取列的值总和,但得到#VALUE!

我首先使用了 SUM 公式,但得到了同样的错误。这是一个示例代码。

for (int x = 2; x <= totalIteration; x++)
{
    startperiodletter = ColumnIndexToColumnLetter(x) + 2;
    endperiodletter = ColumnIndexToColumnLetter(x) + totalrows;
    tmpCell = ColumnIndexToColumnLetter(x) + (totalrows+1);

    ws.Cells[tmpCell].Formula = "=SUMIFS(B2:B99,B2:B99,>0)";
    ws.Cells[tmpCell].Calculate();
    val = (ws.Cells[tmpCell].Value == null ? "" : ws.Cells[tmpCell].Value.ToString());
}

ws.Cells[tmpCell].Formula = "=SUMIFS(B2:B99,B2:B99,>0)"; 通过这种方式,我将SUMIF 公式与 EPPLus 一起使用,当我尝试读取值时,会得到像#VALUE 这样的值!我以这种方式读取值val = (ws.Cells[tmpCell].Value == null ? "" : ws.Cells[tmpCell].Value.ToString());

这条线没有按预期工作。我的几个单元格是空的,我想得到那些不为空的单元格值的总和。

请纠正我在上面的代码中犯的错误。

标签: c#excelepplus

解决方案


推荐阅读