Skip to content

The numFmt tag in the workbook file is missing the formatCode attribute value #1412

Description

@lianglanzheng

NPOI Version

2.7.1

File Type

  • XLSX
  • XLS
  • DOCX
  • XLSM
  • OTHER

Upload the Excel File

EmptyFormatCode.xlsx

Reproduce Steps

Just open and save the file with NPOI, sample code written in .NET 6:

using NPOI.XSSF.UserModel;

string path = "EmptyFormatCode.xlsx";

XSSFWorkbook workbook;
using (FileStream file = new(path, FileMode.Open, FileAccess.Read))
{
    workbook = new(file);
    file.Close();
}
using (FileStream file = new(path, FileMode.Truncate, FileAccess.Write))
{
    workbook.Write(file);
    file.Close();
}
workbook.Close();

Issue Description

When the formatCode attribute value of the numFmt tag in /xl/styles.xml in the workbook archive is an empty string "", NPOI will treat it as a null value and generate the following form xml:

<numFmt numFmtId="0"/>

The current version of Excel does not seem to accept a formatCode value of null and prompts the following error:

image
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfile_errorfile format generation/writing issuexssf

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions