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

Named cell reference causes the string "undefined" to be output in the ODS file #1717

Open
dandv opened this issue Jan 6, 2020 · 1 comment
Open

Comments

@dandv
Copy link

@dandv dandv commented Jan 6, 2020

const XLSX = require('xlsx');

const wb = XLSX.utils.book_new();

const ws = XLSX.utils.json_to_sheet([]);

XLSX.utils.book_append_sheet(wb, ws, 'Bug sheet');

ws.A1 = { t: 's', f: 'square' };

XLSX.writeFile(wb, 'formula.ods');

The resulting .ODS file contains:

<table:table-cell table:formula="of:=square" office:value-type="string"><text:p>undefined</text:p></table:table-cell>

Not sure what <text:p> is (probably a placeholder?), but it should simply be omitted in this case.

Adding a v: '' to the cell object outputs an empty <text:p></text:p>.

<table:table-cell table:formula="of:=square" office:value-type="string"><text:p></text:p></table:table-cell>

That, again, should be omitted, or optimized to <text:p/>.

@SheetJSDev
Copy link
Contributor

@SheetJSDev SheetJSDev commented Jan 7, 2020

This is actually an issue with a string cell that has no value. The fix is pretty straightforward (feel free to submit a PR): https://github.com/SheetJS/sheetjs/blob/master/bits/81_writeods.js#L81

-						textp = cell.v;
+						textp = cell.v == null ? "" : cell.v;
djrumph added a commit to djrumph/sheetjs that referenced this issue Jan 23, 2020
I saw the issue was raised and a SheetJS Dev said the fix was simple and involved dealing with defined and undefined variables.
They wrote a line using a ternary conditional to assign the variable textp to the value of cell.v if it's defined, or an empty string if it is not defined. 

SheetJS Dev Code: textp = cell.v == null ? "" : cell.v;

Suggesting using the line: textp = cell.v || "";

This does the same thing and assigns textp to cell.v if it is defined or an empty string if it is not. 

(Note any feedback would be greatly appreciated, this is my first try at contributing to open source).
geoffrymichael added a commit to geoffrymichael/sheetjs that referenced this issue Feb 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.