Unable to read correct data when excel sheet has both datetime and numbers fields
skumlk opened this issue · comments
i'm reading following excel sheet. But when rawNumbers is true, it messes up datetime and time data. And when raw is false, then it show numbers in scientific format. Is there any other way to read all three data types (numbers, date and datetime) without any formatting as in excel sheet.
First 22261438612413 10:25:00 AM 2021-05-12
let XLSX = require("xlsx");
let wb = XLSX.readFile("./test.xlsx", { type: 'binary' });
let wsname = wb.SheetNames[0];
let ws = wb.Sheets[wsname];
let excelData = XLSX.utils.sheet_to_json(ws, { header: 1, blankrows: false, rawNumbers: true });
console.log(excelData);
excelData = XLSX.utils.sheet_to_json(ws, { header: 1, raw: false });
console.log(excelData);
Output is
[ [ 'First', 22261438612413, 0.434027777777778, 44328 ] ]
[ [ 'First', '2.22614E+13', '10:25:00 AM', '2021-05-12' ] ]
Pass the option cellDates: true
to XLSX.readFile
to force date objects:
let wb = XLSX.readFile("./test.xlsx", { type: 'binary', cellDates: true });
I had the same issue and I was using the option cellDates: true
Pass the option
cellDates: true
toXLSX.readFile
to force date objects:let wb = XLSX.readFile("./test.xlsx", { type: 'binary', cellDates: true });
helpful for me, thanks!