Skip to content

Formula evaluation fails (ErrorCode 15) when using TEXT() function with date #1787

@SDNA-ALP

Description

@SDNA-ALP

NPOI Version

2.7.5

File Type

  • XLSX

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;
        }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions