Comments in empty cells lost when reading XLS files #1567

Closed
opened 2019-07-16 12:56:14 +00:00 by Krelborn · 2 comments
Krelborn commented 2019-07-16 12:56:14 +00:00 (Migrated from github.com)

I am writing a tool that abstracts data stored in cell notes by an Excel add-in. I have found a problem where xlsx does not create the cell objects for cells with notes that have no data. This is only a problem for files saved as XLS. For XLSX there appears to be an empty string data entry for the cell that causes the object to be created.

Would it possible to fix this, so when reading note entries, if the cell object does not exist one is created instead of throwing away the note data?

Attached a very simple example where Sheet1!A1 contains note but no cell data.

test.zip

I am writing a tool that abstracts data stored in cell notes by an Excel add-in. I have found a problem where xlsx does not create the cell objects for cells with notes that have no data. This is only a problem for files saved as XLS. For XLSX there appears to be an empty string data entry for the cell that causes the object to be created. Would it possible to fix this, so when reading note entries, if the cell object does not exist one is created instead of throwing away the note data? Attached a very simple example where Sheet1!A1 contains note but no cell data. [test.zip](https://github.com/SheetJS/js-xlsx/files/3397094/test.zip)
SheetJSDev commented 2019-07-29 09:35:40 +00:00 (Migrated from github.com)

yeah the fix is fairly straightforward:

-                                       if(!cc) break;
+                                       if(!cc) {
+                                               if(options.dense) {
+                                                       if(!out[val[0].r]) out[val[0].r] = [];
+                                                       cc = out[val[0].r][val[0].c] = {t:"z"};
+                                               } else {
+                                                       cc = out[encode_cell(val[0])] = {t:"z"};
+                                               }
+                                               range.e.r = Math.max(range.e.r, val[0].r);
+                                               range.s.r = Math.min(range.s.r, val[0].r);
+                                               range.e.c = Math.max(range.e.c, val[0].c);
+                                               range.s.c = Math.min(range.s.c, val[0].c);
+                                       }

This should be applied to bits/76_xls.js starting around line 534. After building, it will apply to xlsx.js at about line 16874 and xlsx.flow.js at around 16988. Feel free to make the change and submit a PR.

yeah the fix is fairly straightforward: ```diff - if(!cc) break; + if(!cc) { + if(options.dense) { + if(!out[val[0].r]) out[val[0].r] = []; + cc = out[val[0].r][val[0].c] = {t:"z"}; + } else { + cc = out[encode_cell(val[0])] = {t:"z"}; + } + range.e.r = Math.max(range.e.r, val[0].r); + range.s.r = Math.min(range.s.r, val[0].r); + range.e.c = Math.max(range.e.c, val[0].c); + range.s.c = Math.min(range.s.c, val[0].c); + } ``` This should be applied to `bits/76_xls.js` starting around line 534. After building, it will apply to `xlsx.js` at about line 16874 and `xlsx.flow.js` at around 16988. Feel free to make the change and submit a PR.
Krelborn commented 2019-08-05 08:05:13 +00:00 (Migrated from github.com)

I just tested against the latest version and can confirm my problem is now fixed. Thanks for getting the fix out so quickly.

I just tested against the latest version and can confirm my problem is now fixed. Thanks for getting the fix out so quickly.
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#1567
No description provided.