Excel sheet to - Date Issue - XLSX Package
Hi Team ,
I am struggling with date format .
my package.json
{ "name": "test", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "xlsx": "^0.14.0" } }
find my xlsx file in the attachment 100264.xlsx and i am using below code in node js to read the file but the date is one day before . Also numeric field are not coming properly . please suggest ho to handle these issues
const XLSX = require('xlsx');
var workbook = XLSX.readFile('100264.xlsx',{type: 'binary', cellDates: true, dateNF: 'mm/dd/yyyy;@'}); //var workbook = XLSX.readFile('100264.xlsx',{type: 'binary', cellDates: true}); //var workbook = XLSX.readFile('100264.xlsx',{type: 'binary',cellDates: true}); let active_sheet_name = workbook.SheetNames[0]; let fileData = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[active_sheet_name]);
console.log(fileData);
the output of console.log is given below.
[ { 'Sales Date': 2018-01-30T18:30:00.000Z }, { 'Sales Date': 2018-01-30T18:30:00.000Z }, { 'Sales Date': 2018-01-30T18:30:00.000Z }, { 'Sales Date': 2018-01-30T18:30:00.000Z }, { 'Sales Date': 2018-01-30T18:30:00.000Z }, { 'Sales Date': 2018-01-30T18:30:00.000Z }, { 'Sales Date': 2018-01-30T18:30:00.000Z }, { 'Sales Date': 2018-01-30T18:30:00.000Z }, { 'Sales Date': 2018-01-30T18:30:00.000Z }, { 'Sales Date': 2018-01-30T18:30:00.000Z }, { 'Sales Date': 2018-01-30T18:30:00.000Z }, { 'Sales Date': 2018-01-30T18:30:00.000Z }, { 'Sales Date': 2018-01-30T18:30:00.000Z }, { 'Sales Date': 2018-01-30T18:30:00.000Z }, { 'Sales Date': 2018-01-30T18:30:00.000Z }, { 'Sales Date': 2018-01-30T18:30:00.000Z }, { 'Sales Date': 2018-01-30T18:30:00.000Z }, { 'Sales Date': 2018-03-01T18:30:00.000Z } ]
The default passes dates as raw date objects. To recover the text in the original format, use the option raw: false, as answered in https://github.com/SheetJS/js-xlsx/issues/703#issuecomment-432781209
Hi Reviewher Thanks for the reply but now i am getting exact value as in excel file but i need the actual as you can see last formats . there is no year .so basically i have applied different format for each cell and but in behind each cell have proper date as you can see in my excel file so i need the actual in mm/dd/ yyyy format or any other specific format. Please reply..
Thursday, January 12, 2012 2013-01-25 1/21 1/31/18 01/12/11 31-Jan 31-Jan-19 Jan-20 January-22 May 25, 2013 12/19/17 12:00 AM 1/31/18 0:00 J J-18 J-18 J-18 M-18 01/03/2017
Sure, you additionally need cellText: false on the read part. That will ensure the raw text isn't generated, so when the conversion happens it will use the new format.
Hi Reviewher ,
Thanks once again I have applied cellText: false now it is taking every year is 2000 century for example:-
03/01/1901 in excel 03/01/2001 in node js