Skip to content

NullReferenceException when calculating named array constants containing error literals #2218

@hershaw

Description

@hershaw

EPPlus usage

Commercial use (I have a commercial license)

Environment

macOS 15.6 (arm64) running .NET SDK 8.0.416 / .NET runtime 8.0.22

Epplus version

8.3.1

Spreadsheet application

None (headless library usage)

Description

Program to reproduce:

using OfficeOpenXml;
using OfficeOpenXml.FormulaParsing;

ExcelPackage.License.SetNonCommercialPersonal("epplus-nullref-repro");

var fatalCases = new (string Name, string Formula, string Description)[]
{
    ("Div0Literal", "{#DIV/0!}", "Single-item array constant that contains #DIV/0!."),
    ("NullLiteral", "{#NULL!}", "Single-item array constant that contains #NULL!."),
    ("NameLiteral", "{#NAME?}", "Single-item array constant that contains #NAME?."),
    ("GettingDataLiteral", "{#GETTING_DATA}", "Single-item array constant that contains #GETTING_DATA.")
};

foreach (var (name, formula, description) in fatalCases)
{
    using var package = new ExcelPackage();
    var worksheet = package.Workbook.Worksheets.Add("Assumption Sheet");
    worksheet.Cells["A1"].Value = 1;

    package.Workbook.Names.AddFormula(name, formula);

    package.Workbook.Calculate(new ExcelCalculationOption { AllowCircularReferences = true });
}

Actual result: ExcelWorkbook.Calculate throws a NullReferenceException for every formula above.

Expected result: Calculating a workbook-level named formula that is a single-item array constant containing an Excel error literal should either succeed or return the corresponding Excel error value.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions