Skip to content

[BUG] Errors when opening file in Excel after saving a file with conditional formatting #1305

Closed
@glen-84

Description

@glen-84

🐛 Bug Report

Lib version: 3.9.0

Steps To Reproduce

const Excel = require("exceljs");
const fs = require("fs");

const inputFilePath = "input.xlsx";
const outputFilePath = "output.xlsx";

(async () => {
    const workbook = new Excel.Workbook();

    const data = await fs.promises.readFile(inputFilePath);

    await workbook.xlsx.load(data.buffer);

    // Write.
    await fs.promises.writeFile(outputFilePath, await workbook.xlsx.writeBuffer());
})().catch((e) => console.error(e));

input.xlsx
output.xlsx

Opening the output file with Excel results in the following:

image

<? version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  <logFileName>
    error043120_01.xml
  </logFileName>
  <summary>
    Errors were detected in file 'C:\Users\Rob\Documents\glen-tmp\output.xlsx'
  </summary>
  <removedParts summary="Following is a list of removed parts:">
    <removedPart>
      Removed Part: /xl/styles.xml part with XML error.  (Styles) Load error. Line 2, column 6585.
    </removedPart>
  </removedParts>
  <repairedRecords summary="Following is a list of repairs:">
    <repairedRecord>
      Repaired Records: Cell information from /xl/worksheets/sheet2.xml part
    </repairedRecord>
    <repairedRecord>
      Repaired Records: Column information from /xl/worksheets/sheet2.xml part
    </repairedRecord>
    <repairedRecord>
      Repaired Records: Conditional formatting from /xl/worksheets/sheet2.xml part
    </repairedRecord>
  </repairedRecords>
</recoveryLog>

Just opening and saving the file causes the file size to go from 33 KB to 14 KB. 😮

If I clear the conditional formatting in the input file, then I don't see the errors (although the file size still drops dramatically, which is a bit worrying).

The expected behaviour:

No errors when opening the file in Excel, and possibly more similar file size of input and output files.

Possible solution (optional, but very helpful):

n/a


Edit: Here's a smaller reproduction:

simple3-input.xlsx
simple3-output.xlsx

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