Skip to content

Date format string exception #2257

@hershaw

Description

@hershaw

EPPlus usage

Commercial use (I have a commercial license)

Environment

OSX

Epplus version

8.4.0

Spreadsheet application

excel

Description

If I open a date formatted like this in excel, it renders. but in EPPlus it throws an error.

public void EPPlus_ThrowsFormatException_ForMalformedDateFormat()
    {
        using var pkg = new ExcelPackage();
        var ws = pkg.Workbook.Worksheets.Add("Test");

        ws.Cells["A1"].Value = new DateTime(2024, 12, 31);

        ws.Cells["A1"].Style.Numberformat.Format = "[$-en-US]mmm d, 'yy;@";

        // Directly accessing cell.Text should throw FormatException
        // This documents the bug that our workaround addresses
        var ex = Assert.Throws<FormatException>(() => ws.Cells["A1"].Text);
        Assert.Contains("quote", ex.Message, StringComparison.OrdinalIgnoreCase);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions