NPOI Version
2.7.5
File Type
Upload the Excel File
Test.xlsx
Reproduce Steps
Evaluate cell I2 using IFormulaEvaluator.Evaluate()
Expected
Same result as in Excel
Actual
CellType = Error
ErrorCode = 15
But ICell.StringCellValue returns the correct value
Observation
The issue seems caused by the formula:
TEXT(L2;"dd/mm/yyyy")
If this part is removed, the evaluation works correctly.
Code
/// <summary></summary>
private string xReadValueStr_Formula(ISheet Sheet, ICell Cell)
{
// Declare the variables
IFormulaEvaluator mFormulaEvaluator;
CellValue mCellValue;
string mResult;
// Evaluate the formula
mFormulaEvaluator = Sheet.Workbook.GetCreationHelper().CreateFormulaEvaluator();
// Get the cell value
mCellValue = mFormulaEvaluator.Evaluate(Cell);
// Set the result
mResult = mCellValue.CellType switch
{
CellType.Numeric => mCellValue.NumberValue.ToString(),
CellType.String => mCellValue.StringValue,
CellType.Boolean => mCellValue.BooleanValue.ToString(),
CellType.Blank => string.Empty,
CellType.Unknown => string.Empty,
CellType.Formula => string.Empty,
CellType.Error => string.Empty, <-- I2 cell returns string.Empty because CelType value is Error -->
_ => mCellValue.FormatAsString(),
};
// Return the result
return mResult;
}
NPOI Version
2.7.5
File Type
Upload the Excel File
Test.xlsx
Reproduce Steps
Evaluate cell I2 using IFormulaEvaluator.Evaluate()
Expected
Same result as in Excel
Actual
CellType = Error
ErrorCode = 15
But ICell.StringCellValue returns the correct value
Observation
The issue seems caused by the formula:
TEXT(L2;"dd/mm/yyyy")
If this part is removed, the evaluation works correctly.
Code