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

Closed
opened 2020-01-06 05:13:52 +00:00 by dandv · 1 comment
dandv commented 2020-01-06 05:13:52 +00:00 (Migrated from github.com)
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/>.

```js 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 commented 2020-01-07 04:37:56 +00:00 (Migrated from github.com)

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;
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 ```diff - textp = cell.v; + textp = cell.v == null ? "" : cell.v; ```
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#1717
No description provided.