As of EpPlus version 4.0.1.1, there is an extension method Calculate(this ExcelRangeBase range)
. Invoke it:
cell.Calculate();
and after that the cell.Value
will return the expected result.
UPDATE
From the official documentation:
EPPlus supports formula calculation from version 4. This means that you can let EPPlus calculate the results of the formulas in a workbook.
This is done by calling the Calculate() method, which is available on Workbook, Worksheet and Range level. When Calculate() is called EPPlus will evaluate the result of the formula and store the result as the Value of the cell - just like Excel do.
Example
using(var package = new ExcelPackage(new FileInfo(@"c:\temp\tmp.xlsx")))
{
// calculate all formulas in the workbook
package.Workbook.Calculate();
// calculate one worksheet
package.Workbook.Worksheets["my sheet"].Calculate();
// calculate a range
package.Workbook.Worksheets["my sheet"].Cells["A1"].Calculate();
}
Known issues
The following features of Excel are currently not supported by EPPlus when it comes to Formula caluclation: Array Formulas, the Intersect operator, references to external workbooks.