Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue: style.xml has [Object object] as formatCode #2698

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jmatth11
Copy link

@jmatth11 jmatth11 commented Feb 20, 2024

Summary

Somehow the excel file is in a state where exceljs does not handle extracting the numFmt of a DXF conditional format properly and instead has it set to an object.

This results in the generate style.xml file to have a formatCode of [Object object] inside which corrupts the file.

This fix is to check if the numFmt is of the appropriate string type and if not, corrects it by extracting the formatCode before moving forward on the prepare step of writing.

Test plan

This is the test Excel file I used which has a conditional format on A1:C1 which conditional changes the fill color to yellow and the format to be a custom number format if A1 equals "NO".

CF1.xlsx

I setup a simple main.js to read in the test Excel file and write a new file temp.xlsx.

const ExcelJS = require("exceljs");
const workbook = new ExcelJS.Workbook();
workbook.xlsx.readFile("CF1.xlsx").then(() => {
  workbook.xlsx.writeFile("temp.xlsx");
});

With current master branch the result of opening the generated file is this:

original_error original_error_repair_report

After repair conditional formatting is removed.

original_error_cf_removed

Screenshot of xl/style.xml file with the error:

original_xml_file

After the fix the file is generated properly and conditional formatting works as expected.

after_fix

Screenshot of xl/style.xml with fixed format code:

after_fix_xml_file

Related to source code (for typings update)

I'm not really sure what is supposed to go here.

Somehow the excel file is in a state where exceljs does not handle
extracting the numFmt of a conditional format properly and instead has
it set to an object.

This results in the generate style.xml file to have a formatCode of
`[Object object]` inside which corrupts the file.

This fix is to check if the numFmt is of the appropriate string type and
if not, corrects it by extracting the formatCode before moving forward.
Co-authored-by: patra-nash-stokes <151550572+patra-nash-stokes@users.noreply.github.com>
@thestuckster
Copy link

lgtm

@Ks89
Copy link

Ks89 commented Mar 4, 2024

I found the same problem, please could you merge and publish a patch release.
Thanks.

@alex-mazzariol
Copy link

We're finding this issue too when updating an existing excel file that has conditional formatting for some cells. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants