Excel limits the number of custom number formats in a workbook (Microsoft documents this as "between 200 and 250, depending on the language version"). ExcelJS will write more than this without complaint, but the resulting file fails to open cleanly in Excel — Excel reports that it "found a problem with some content" and offers to repair it, silently dropping number formats in the process.
There is currently no way to detect that a workbook is approaching or exceeding this limit before writing, so the problem only surfaces when an end user opens the file in Excel.
Steps to reproduce
const wb = new ExcelJS.Workbook();
const ws = wb.addWorksheet('s');
for (let i = 0; i < 250; i++) {
const cell = ws.getCell(i + 1, 1);
cell.value = i;
cell.numFmt = `0.0" ${i}"`; // 250 distinct custom formats
}
await wb.xlsx.writeFile('out.xlsx');
Expected
Either a way to enforce a maximum number of custom formats, or at least an API to query the current count so callers can avoid producing a file Excel cannot open.
Actual
The file is written with all formats and Excel prompts to repair it on open.
Excel limits the number of custom number formats in a workbook (Microsoft documents this as "between 200 and 250, depending on the language version"). ExcelJS will write more than this without complaint, but the resulting file fails to open cleanly in Excel — Excel reports that it "found a problem with some content" and offers to repair it, silently dropping number formats in the process.
There is currently no way to detect that a workbook is approaching or exceeding this limit before writing, so the problem only surfaces when an end user opens the file in Excel.
Steps to reproduce
Expected
Either a way to enforce a maximum number of custom formats, or at least an API to query the current count so callers can avoid producing a file Excel cannot open.
Actual
The file is written with all formats and Excel prompts to repair it on open.