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

Export of simple json to xlsx file causes error in EXCEL #2720

Closed
lemonbob opened this issue Jun 16, 2022 · 4 comments
Closed

Export of simple json to xlsx file causes error in EXCEL #2720

lemonbob opened this issue Jun 16, 2022 · 4 comments

Comments

@lemonbob
Copy link

lemonbob commented Jun 16, 2022

When exporting a simple JSON to xlsx, EXCEL throws the following error and claims to need to repair file.
excel_error

On repairing the file, EXCEL report the following error in its log

<repairedRecord>Repaired Records: Worksheet properties from /xl/workbook.xml part (Workbook)</repairedRecord>

The JSON file exported is a very simple test file - see below

[
{series name: 'Compliance/Legal', x: '0.5', y: '0.5', value: '1'},
{series name: 'People', x: '4.5', y: '3.5', value: '1'},
{series name: 'Brexit', x: '0.5', y: '4.5', value: '1'},
{series name: 'Business Plan', x: '0.5', y: '4.5', value: '2'}
]

code used to create the file is as follows:

let workSheet = $XLSX.utils.json_to_sheet(data, {header: ['series name', 'x', 'y', 'value']});
let wb = $XLSX.utils.book_new();
$XLSX.utils.book_append_sheet(wb, workSheet, fileName);
$XLSX.writeFile(wb, fileName, {bookType: 'xlsx'});

Please advise.

@SheetJSDev
Copy link
Contributor

You gave everything except for the part causing problems :/

The error message suggests that the worksheet name may be causing issues. What is fileName and can you share the bad file?

To be sure this is not a normal occurrence, here's an example using your exact data: https://jsfiddle.net/gb2hakmd/

const fileName = "issue2720.xlsx";

const data = [
{'series name': 'Compliance/Legal', x: '0.5', y: '0.5', value: '1'},
{'series name': 'People', x: '4.5', y: '3.5', value: '1'},
{'series name': 'Brexit', x: '0.5', y: '4.5', value: '1'},
{'series name': 'Business Plan', x: '0.5', y: '4.5', value: '2'}
];

let workSheet = XLSX.utils.json_to_sheet(data, {header: ['series name', 'x', 'y', 'value']});
let wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, workSheet, fileName);
XLSX.writeFile(wb, fileName, {bookType: 'xlsx'});

@lemonbob
Copy link
Author

lemonbob commented Jun 19, 2022

Hi, yes, no problem. Attached is the file and the fileName is: RiskThemes_ Bubble Chart.xlsx.

RiskThemes_ Bubble Chart.xlsx

I tried exporting with a fileName of test.xlsx and you are correct, it is fine, but I don't see anything wrong with the filename RiskThemes_ Bubble Chart.xlsx - it seems perfectly valid to me? Any ideas?

@backfromexile
Copy link

Hey there, I just had the same problem, but managed to find a fix.
In my case one of the sheet names had a colon : in the name which Excel apparently does not like.
I removed the colon and the shown error message disappared.

@SheetJSDev could validation of the sheet names be possible?

@SheetJSDev
Copy link
Contributor

That was added in 0.18.10. Discussion continued in #2722

@SheetJS SheetJS locked and limited conversation to collaborators Jul 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants