diff --git a/bits/90_utils.js b/bits/90_utils.js index 7628e4a..6feb4ef 100644 --- a/bits/90_utils.js +++ b/bits/90_utils.js @@ -30,7 +30,7 @@ function sheet_to_json(sheet/*:Worksheet*/, opts/*:?Sheet2JSONOpts*/) { case 2: hdr[C] = cols[C]; break; case 3: hdr[C] = o.header[C - r.s.c]; break; default: - if(val == null) continue; + if(val == null) val = {w: "__EMPTY", t: "s"}; vv = v = format_cell(val, null, o); counter = 0; for(CC = 0; CC < hdr.length; ++CC) if(hdr[CC] == vv) vv = v + "_" + (++counter); diff --git a/test.js b/test.js index 3845f9c..eb16db8 100644 --- a/test.js +++ b/test.js @@ -1673,6 +1673,15 @@ describe('json output', function() { assert.equal(json1[2][1], 5); assert.equal(json1[2][3], 3); }); + it('should preserve values when column header is missing', function() { + /*jshint elision:true */ + var _data = [[,"a","b",,"c"], [1,2,3,,5],[,3,4,5,6]]; + /*jshint elision:false */ + var _ws = X.utils.aoa_to_sheet(_data); + var json1 = X.utils.sheet_to_json(_ws, { raw: true }); + assert.equal(json1[0].__EMPTY, 1); + assert.equal(json1[1].__EMPTY_1, 5); + }); }); diff --git a/tests/core.js b/tests/core.js index 3845f9c..eb16db8 100644 --- a/tests/core.js +++ b/tests/core.js @@ -1673,6 +1673,15 @@ describe('json output', function() { assert.equal(json1[2][1], 5); assert.equal(json1[2][3], 3); }); + it('should preserve values when column header is missing', function() { + /*jshint elision:true */ + var _data = [[,"a","b",,"c"], [1,2,3,,5],[,3,4,5,6]]; + /*jshint elision:false */ + var _ws = X.utils.aoa_to_sheet(_data); + var json1 = X.utils.sheet_to_json(_ws, { raw: true }); + assert.equal(json1[0].__EMPTY, 1); + assert.equal(json1[1].__EMPTY_1, 5); + }); }); diff --git a/xlsx.flow.js b/xlsx.flow.js index c57e9ba..a90bb1f 100644 --- a/xlsx.flow.js +++ b/xlsx.flow.js @@ -19036,7 +19036,7 @@ function sheet_to_json(sheet/*:Worksheet*/, opts/*:?Sheet2JSONOpts*/) { case 2: hdr[C] = cols[C]; break; case 3: hdr[C] = o.header[C - r.s.c]; break; default: - if(val == null) continue; + if(val == null) val = {w: "__EMPTY", t: "s"}; vv = v = format_cell(val, null, o); counter = 0; for(CC = 0; CC < hdr.length; ++CC) if(hdr[CC] == vv) vv = v + "_" + (++counter); diff --git a/xlsx.js b/xlsx.js index 891d510..17d6790 100644 --- a/xlsx.js +++ b/xlsx.js @@ -18929,7 +18929,7 @@ function sheet_to_json(sheet, opts) { case 2: hdr[C] = cols[C]; break; case 3: hdr[C] = o.header[C - r.s.c]; break; default: - if(val == null) continue; + if(val == null) val = {w: "__EMPTY", t: "s"}; vv = v = format_cell(val, null, o); counter = 0; for(CC = 0; CC < hdr.length; ++CC) if(hdr[CC] == vv) vv = v + "_" + (++counter);