Skip to content

[BUG] Adding "numFmt" to conditional formatting rule corrupts document #1814

@andreykrupskii

Description

@andreykrupskii

🐛 Bug Report

After specifying numFmt pattern as a style for conditional formatting rule, MS Excel states a problem during opening generated file. The issue is reproducible for both basic and streaming APIs.

issue

Lib version: 4.2.1
MS Excel version: 16.52
OS: MacOS Big Sur (11.4)

Steps To Reproduce

For issue reproduction, next snippet is suggested (run it and try to open generated file):

const Excel = require('exceljs');

const { WorkbookWriter } = Excel.stream.xlsx;

(async () => {
    const workbook = new WorkbookWriter({ filename: 'test.xlsx', useStyles: true });
    const worksheet = workbook.addWorksheet('example');

    worksheet.addConditionalFormatting({
        ref: 'A1:A2',
        rules: [{
            type: 'cellIs',
            operator: 'between',
            formulae: [0, 10],
            style: { numFmt: '0.00' },
            priority: 1,
        }],
    });

    [5.5, 15.5].forEach((value, index) => {
        const row = worksheet.getRow(index + 1);
        const cell = row.getCell(1);
        cell.value = value;
        row.commit();
    });

    worksheet.commit();
    await workbook.commit();
})();

Expected Behavior

The file should be generated validly and it should contain specified conditional formatting rules.

Investigation Notes

The issue is described by an invalid numFmt tag inside styles.xml:

<dxfs count="1">
        <dxf>
            <numFmt/>
        </dxf>
</dxfs>

While valid markup should look like:

<dxfs count="1">
        <dxf>
             <numFmt numFmtId="number" formatCode="0.00"/>
        </dxf>
</dxfs>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions