In that case you can go with 2 options, or either use the ICell.CachedFormulaResultType which gives you the CellType of the actual result of that Formula and then parse that or you can go with Workbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateInCell(ICell) which basically evaluates the formula and replaces that with the ACTUAL Value in the cell.
If you go with the first approach, you can create an extension method and do something like :
If you go with the first approach, you can create an extension method and do something like :
public static object GetValue(this ICell cell, CellType cellType)
{
object value = null;
switch (cellType)
{
case CellType.STRING:
{
value = cell.StringCellValue;
break;
}
case CellType.FORMULA:
{ //If its a Formula, get the Actual Value not the formula itself.
value = cell.GetValue(cell.CachedFormulaResultType);
break;
}
---- rest of code