Is it possible to read the excel cell value with formula?

给你一囗甜甜゛ 提交于 2021-01-03 05:50:37

问题


In my following code, the value of c4 is coming out zero. C4 cell has formula SUM(C2:C3). Is EPPlus capable of reading cell with formula? Why is c4 being set to zero instead of 12.

using (var package = new ExcelPackage(existingFile))
{
    ExcelWorkbook workBook = package.Workbook;
    var currentWorksheet = workBook.Worksheets.First();

    currentWorksheet.Cells["C2"].Value = 5;
    currentWorksheet.Cells["C3"].Value = 7;
    var c4 = Convert.ToDouble(currentWorksheet.Cells["C4"].Value); //c4 is zero. why?
}

回答1:


As of EpPlus 4.0.1.1, there is an extension method public static void Calculate(this ExcelRangeBase range). Invoke it prior to accessing C4's Value property:

currentWorksheet.Cells["C4"].Calculate();

and currentWorksheet.Cells["C4"].Value will return 12 after that.



来源:https://stackoverflow.com/questions/21213106/is-it-possible-to-read-the-excel-cell-value-with-formula

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!