sheet_to_json doesn't output anything for a blank cell
See original GitHub issueIt seems like using sheet_to_json doesn’t handle blank cells very well. I want to keep them in my script (I’m parsing an xlsx file and outputting a csv), but a blank cell outputs an array like:
[ 'foo',
'bar',
, // the blank value
'another value' ]
It’d be nice if you got a blank string, since this library seems to recognize the blank value. Would this be possible?
Issue Analytics
- State:
- Created 9 years ago
- Comments:18 (1 by maintainers)
Top Results From Across the Web
javascript - sheetJs - no output for empty cell - Stack Overflow
data is just a const which holds conversion from sheet to json ... using for conversion and manipulation; defval presents empty cell values....
Read more >Utility Functions - SheetJS Community Edition
aoa_to_sheet takes an array of arrays of JS values and returns a worksheet resembling the input data. Values are interpreted as follows: Numbers,...
Read more >How to remove blank cells in Excel - Ablebits
Empty cells are removed. Tips: If something has gone awry, don't panic and immediately press Ctrl + Z to get your data ...
Read more >xlsx.utils.sheet_to_json | The AI Search Engine You Control
I am trying to convert an Excel worksheet into a JSON object using the built in node module XLSX' function XLSX.utils.sheet_to_json() However, ...
Read more >How to Determine IF a Cell is Blank or Not Blank in Excel
Want to learn more about the IF function? This post will give you an overview of how to use an IF function when...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
you don’t need to change anythings, just in function pass opt defval:‘’ that’s it.
The code as it stands now won’t generate an empty string. The simplest way is to just add a post-processing loop to your code:
As for what it “should” be, why not the number 0? an empty string would be weird in a case like:
I’d be amenable to adding an option (maybe something called “default” in the options object?), and the changes are relatively simple: https://github.com/SheetJS/js-xlsx/blob/master/xlsx.js#L5293
In the bottom half of sheet_to_json, we walk in row-major order across the worksheet. The first line attempts to find if the sheet has a cell at the prescribed address. If the cell doesn’t exist or if its type is not set, then we skip the cell. Instead of just continuing, that second line should set the cell to the empty string: