是否有可能读取公式的Excel单元格值?

在我的下面的代码中,c4的值是零。 C4单元具有公式SUM(C2:C3)。 EPPlus是否可以通过配方来读取细胞? 为什么c4被设置为零而不是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? } 

从EpPlus 4.0.1.1开始,有一个扩展方法public static void Calculate(this ExcelRangeBase range) 。 在访问C4的Value属性之前调用它:

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

currentWorksheet.Cells["C4"].Value之后返回12