forked from sheetjs/sheetjs
Fix rawNumber support inside sheet_to_json
This commit is contained in:
parent
69bb1e79a3
commit
a5b387716c
@ -34,7 +34,7 @@ function make_json_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Ar
|
||||
else if(raw && v === null) row[hdr[C]] = null;
|
||||
else continue;
|
||||
} else {
|
||||
row[hdr[C]] = raw || (o.rawNumbers && val.t == "n") ? v : format_cell(val,v,o);
|
||||
row[hdr[C]] = raw && (val.t !== "n" || (val.t === "n" && o.rawNumbers !== false)) ? v : format_cell(val,v,o);
|
||||
}
|
||||
if(v != null) isempty = false;
|
||||
}
|
||||
|
16
test.js
16
test.js
@ -144,6 +144,8 @@ var paths = {
|
||||
dtxlsx: dir + 'xlsx-stream-d-date-cell.xlsx',
|
||||
dtxlsb: dir + 'xlsx-stream-d-date-cell.xlsb',
|
||||
|
||||
dtfxlsx: dir + 'DataTypesFormats.xlsx',
|
||||
|
||||
fstxls: dir + 'formula_stress_test.xls',
|
||||
fstxml: dir + 'formula_stress_test.xls.xml',
|
||||
fstxlsx: dir + 'formula_stress_test.xlsx',
|
||||
@ -1381,6 +1383,20 @@ describe('parse features', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('data types formats', function() {[
|
||||
['xlsx', paths.dtfxlsx],
|
||||
].forEach(function(m) { it(m[0], function() {
|
||||
var wb = X.read(fs.readFileSync(m[1]), {type: TYPE, cellDates: true});
|
||||
var ws = wb.Sheets[wb.SheetNames[0]];
|
||||
var data = X.utils.sheet_to_json(ws, { header: 1, raw: true, rawNumbers: false });
|
||||
assert(data[0][1] instanceof Date);
|
||||
assert(data[1][1] instanceof Date);
|
||||
assert.equal(data[2][1], '$123.00');
|
||||
assert.equal(data[3][1], '98.76%');
|
||||
assert.equal(data[4][1], '456.00');
|
||||
assert.equal(data[5][1], '7,890');
|
||||
}); }); });
|
||||
});
|
||||
|
||||
describe('write features', function() {
|
||||
|
16
test.mjs
generated
16
test.mjs
generated
@ -145,6 +145,8 @@ var paths = {
|
||||
dtxlsx: dir + 'xlsx-stream-d-date-cell.xlsx',
|
||||
dtxlsb: dir + 'xlsx-stream-d-date-cell.xlsb',
|
||||
|
||||
dtfxlsx: dir + 'DataTypesFormats.xlsx',
|
||||
|
||||
fstxls: dir + 'formula_stress_test.xls',
|
||||
fstxml: dir + 'formula_stress_test.xls.xml',
|
||||
fstxlsx: dir + 'formula_stress_test.xlsx',
|
||||
@ -1371,6 +1373,20 @@ describe('parse features', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('data types formats', function() {[
|
||||
['xlsx', paths.dtfxlsx]
|
||||
].forEach(function(m) { it(m[0], function() {
|
||||
var wb = X.read(fs.readFileSync(m[1]), {type: TYPE, cellDates: true});
|
||||
var ws = wb.Sheets[wb.SheetNames[0]];
|
||||
var data = X.utils.sheet_to_json(ws, { header: 1, raw: true, rawNumbers: false });
|
||||
assert.ok(data[0][1] instanceof Date);
|
||||
assert.ok(data[1][1] instanceof Date);
|
||||
assert.equal(data[2][1], '$123.00');
|
||||
assert.equal(data[3][1], '98.76%');
|
||||
assert.equal(data[4][1], '456.00');
|
||||
assert.equal(data[5][1], '7,890');
|
||||
}); }); });
|
||||
});
|
||||
|
||||
describe('write features', function() {
|
||||
|
18
test.ts
18
test.ts
@ -165,6 +165,8 @@ var paths: any = {
|
||||
dtxlsx: dir + 'xlsx-stream-d-date-cell.xlsx',
|
||||
dtxlsb: dir + 'xlsx-stream-d-date-cell.xlsb',
|
||||
|
||||
dtfxlsx: dir + 'DataTypesFormats.xlsx',
|
||||
|
||||
fstxls: dir + 'formula_stress_test.xls',
|
||||
fstxml: dir + 'formula_stress_test.xls.xml',
|
||||
fstxlsx: dir + 'formula_stress_test.xlsx',
|
||||
@ -951,7 +953,7 @@ Deno.test('parse features', async function(t) {
|
||||
X.read(fs.readFileSync(paths.cpxml), {type:TYPE, WTF:true})
|
||||
];
|
||||
|
||||
var s1 = ['XLSX', 'XLSB', 'XLS', 'XML']; for(var i = 0; i < s1.length; ++i) { let x = s1[i];
|
||||
var s1 = ['XLSX', 'XLSB', 'XLS', 'XML']; for(var i = 0; i < s1.length; ++i) { let x = s1[i];
|
||||
await t.step(x + ' should parse core properties', async function(t) { var P = wbs?.[i]?.Props; if(typeof P == "undefined") throw "missing props"; coreprop(P); });
|
||||
await t.step(x + ' should parse custom properties', async function(t) { custprop(wbs?.[i]?.Custprops); });
|
||||
}
|
||||
@ -1335,6 +1337,20 @@ Deno.test('parse features', async function(t) {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
await t.step('data types formats', async function(t) {var dtf = [
|
||||
['xlsx', paths.dtfxlsx]
|
||||
]; for(var j = 0; j < dtf.length; ++j) { var m = dtf[j]; await t.step(m[0], async function(t) {
|
||||
var wb = X.read(fs.readFileSync(m[1]), {type: TYPE, cellDates: true});
|
||||
var ws = wb.Sheets[wb.SheetNames[0]];
|
||||
var data = X.utils.sheet_to_json<any>(ws, { header: 1, raw: true, rawNumbers: false });
|
||||
assert.assert(data[0][1] instanceof Date);
|
||||
assert.assert(data[1][1] instanceof Date);
|
||||
assert.equal(data[2][1], '$123.00');
|
||||
assert.equal(data[3][1], '98.76%');
|
||||
assert.equal(data[4][1], '456.00');
|
||||
assert.equal(data[5][1], '7,890');
|
||||
}); } });
|
||||
});
|
||||
|
||||
Deno.test('write features', async function(t) {
|
||||
|
@ -45,6 +45,7 @@ text_and_numbers.xlsb
|
||||
time_stress_test_1.xlsb.pending
|
||||
xlsx-stream-d-date-cell.xlsb
|
||||
AutoFilter.xlsx
|
||||
DataTypesFormats.xlsx
|
||||
ErrorTypes.xlsx
|
||||
LONumbers-2010.xlsx
|
||||
LONumbers-2011.xlsx
|
||||
|
16
tests/core.js
generated
16
tests/core.js
generated
@ -144,6 +144,8 @@ var paths = {
|
||||
dtxlsx: dir + 'xlsx-stream-d-date-cell.xlsx',
|
||||
dtxlsb: dir + 'xlsx-stream-d-date-cell.xlsb',
|
||||
|
||||
dtfxlsx: dir + 'DataTypesFormats.xlsx',
|
||||
|
||||
fstxls: dir + 'formula_stress_test.xls',
|
||||
fstxml: dir + 'formula_stress_test.xls.xml',
|
||||
fstxlsx: dir + 'formula_stress_test.xlsx',
|
||||
@ -1381,6 +1383,20 @@ describe('parse features', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('data types formats', function() {[
|
||||
['xlsx', paths.dtfxlsx],
|
||||
].forEach(function(m) { it(m[0], function() {
|
||||
var wb = X.read(fs.readFileSync(m[1]), {type: TYPE, cellDates: true});
|
||||
var ws = wb.Sheets[wb.SheetNames[0]];
|
||||
var data = X.utils.sheet_to_json(ws, { header: 1, raw: true, rawNumbers: false });
|
||||
assert(data[0][1] instanceof Date);
|
||||
assert(data[1][1] instanceof Date);
|
||||
assert.equal(data[2][1], '$123.00');
|
||||
assert.equal(data[3][1], '98.76%');
|
||||
assert.equal(data[4][1], '456.00');
|
||||
assert.equal(data[5][1], '7,890');
|
||||
}); }); });
|
||||
});
|
||||
|
||||
describe('write features', function() {
|
||||
|
1
tests/fixtures.js
generated
1
tests/fixtures.js
generated
File diff suppressed because one or more lines are too long
@ -57,6 +57,7 @@
|
||||
./test_files/column_width.xlsb
|
||||
./test_files/column_width.slk
|
||||
./test_files/cross-sheet_formula_names.xlsb
|
||||
./test_files/DataTypesFormats.xlsx
|
||||
./test_files/defined_names_simple.xls
|
||||
./test_files/defined_names_simple.xml
|
||||
./test_files/defined_names_simple.xlsx
|
||||
|
1170
xlsx.flow.js
1170
xlsx.flow.js
File diff suppressed because it is too large
Load Diff
2
xlsx.mjs
generated
2
xlsx.mjs
generated
@ -23553,7 +23553,7 @@ function make_json_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Ar
|
||||
else if(raw && v === null) row[hdr[C]] = null;
|
||||
else continue;
|
||||
} else {
|
||||
row[hdr[C]] = raw || (o.rawNumbers && val.t == "n") ? v : format_cell(val,v,o);
|
||||
row[hdr[C]] = raw && (val.t !== "n" || (val.t === "n" && o.rawNumbers !== false)) ? v : format_cell(val,v,o);
|
||||
}
|
||||
if(v != null) isempty = false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user