sheetStubs causes "unrecognized type stub" in sheet_to_json #382

Closed
opened 2016-03-23 13:48:03 +00:00 by jugaltheshah · 1 comment
jugaltheshah commented 2016-03-23 13:48:03 +00:00 (Migrated from github.com)

Issue: when I set option sheetStubs to true while running XLSX.readFile on a xlsx file, I'll get "unrecognized type stub" if I run XLSX.utils.sheet_to_json on the result.
Edit: Forgot to mention #333 also mentions this issue and there's a pull request against it (#354), but I believe my comments below address the root cause, and the potential fix below may better prevent further downline issues.

Expected behavior: I would think the xlsx package would correctly use the sheetStubs option while parsing a file with empty cells.

Steps to reproduce:

  1. Run XLSX.readFile(filePath,{'sheetStubs': true}) and store the result in an object
  2. For each sheet in the result object, get the sheet object ref (wbObj.Sheets[sheetName]) and run XLSX.utils.sheet_to_json on it

Potential fix:
In xlsx.js on lines 7479 & 7480, it sets p.t = "stub" if opts.sheetStubs is present. However, slightly further down in the switch statement beginning on line 7486 where it's checking for different p.t types, there is nothing matching a p.t value of "stub". I believe case 'str' (7494) is what it should slot into, as case str assigns "s" to p.t and correctly checks for an empty value, assigning an empty string to p.v if so. I tried setting p.t = "str" on line 7480 and it seems to work. Not sure if this is the correct fix though.

Issue: when I set option sheetStubs to true while running XLSX.readFile on a xlsx file, I'll get "unrecognized type stub" if I run XLSX.utils.sheet_to_json on the result. Edit: Forgot to mention #333 also mentions this issue and there's a pull request against it (#354), but I believe my comments below address the root cause, and the potential fix below may better prevent further downline issues. Expected behavior: I would think the xlsx package would correctly use the sheetStubs option while parsing a file with empty cells. Steps to reproduce: 1) Run XLSX.readFile(filePath,{'sheetStubs': true}) and store the result in an object 2) For each sheet in the result object, get the sheet object ref (wbObj.Sheets[sheetName]) and run XLSX.utils.sheet_to_json on it Potential fix: In xlsx.js on lines 7479 & 7480, it sets p.t = "stub" if opts.sheetStubs is present. However, slightly further down in the switch statement beginning on line 7486 where it's checking for different p.t types, there is nothing matching a p.t value of "stub". I believe case 'str' (7494) is what it should slot into, as case str assigns "s" to p.t and correctly checks for an empty value, assigning an empty string to p.v if so. I tried setting p.t = "str" on line 7480 and it seems to work. Not sure if this is the correct fix though.
pimpelsang commented 2016-04-08 10:50:33 +00:00 (Migrated from github.com)

+1 for needing fix

+1 for needing fix
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#382
No description provided.