forked from sheetjs/sheetjs
converting to json with a selected range and header: 1 now lets the array start at zero
This commit is contained in:
parent
95a377c0e4
commit
c6f96c3df7
@ -26,7 +26,7 @@ function sheet_to_json(sheet/*:Worksheet*/, opts/*:?Sheet2JSONOpts*/){
|
||||
cols[C] = encode_col(C);
|
||||
val = dense ? sheet[R][C] : sheet[cols[C] + rr];
|
||||
switch(header) {
|
||||
case 1: hdr[C] = C; break;
|
||||
case 1: hdr[C] = C - r.s.c; break;
|
||||
case 2: hdr[C] = cols[C]; break;
|
||||
case 3: hdr[C] = o.header[C - r.s.c]; break;
|
||||
default:
|
||||
|
9
test.js
9
test.js
@ -1516,6 +1516,15 @@ describe('json output', function() {
|
||||
assert.equal(json5.length, 2); // = 2 records
|
||||
assert.equal(json6.length, 3); // = 4 sheet rows - 1 blank row
|
||||
});
|
||||
it('should have an index that starts with zero when selecting range', function() {
|
||||
var _data = [["S","h","e","e","t","J","S"],[1,2,3,4,5,6,7],[7,6,5,4,3,2,1],[2,3,4,5,6,7,8]];
|
||||
var _ws = X.utils.aoa_to_sheet(_data);
|
||||
var json1 = X.utils.sheet_to_json(_ws, { header:1, raw: true, range: "B1:F3" });
|
||||
assert.equal(json1[0][3], "t");
|
||||
assert.equal(json1[1][0], 2);
|
||||
assert.equal(json1[2][1], 5);
|
||||
assert.equal(json1[2][3], 3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('csv output', function() {
|
||||
|
@ -16562,7 +16562,7 @@ function sheet_to_json(sheet/*:Worksheet*/, opts/*:?Sheet2JSONOpts*/){
|
||||
cols[C] = encode_col(C);
|
||||
val = dense ? sheet[R][C] : sheet[cols[C] + rr];
|
||||
switch(header) {
|
||||
case 1: hdr[C] = C; break;
|
||||
case 1: hdr[C] = C - r.s.c; break;
|
||||
case 2: hdr[C] = cols[C]; break;
|
||||
case 3: hdr[C] = o.header[C - r.s.c]; break;
|
||||
default:
|
||||
|
2
xlsx.js
2
xlsx.js
@ -16492,7 +16492,7 @@ function sheet_to_json(sheet, opts){
|
||||
cols[C] = encode_col(C);
|
||||
val = dense ? sheet[R][C] : sheet[cols[C] + rr];
|
||||
switch(header) {
|
||||
case 1: hdr[C] = C; break;
|
||||
case 1: hdr[C] = C - r.s.c; break;
|
||||
case 2: hdr[C] = cols[C]; break;
|
||||
case 3: hdr[C] = o.header[C - r.s.c]; break;
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user