Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date in XLS sheet not parsing correctly

Tags:

node.js

xlsx

I am trying to read a XLS file using 'XLSX' node-module with a column having dates. After parsing the file what I found is that the dates are of few dates back from that of the dates in the sheet. This is what I a doing.

var workbook = XLSX.readFile(filePath);
var grossPayoutSheet = workbook.Sheets[worksheets[1]];
for (var i in grossPayoutSheet) {
				if (i[0] === "!") continue;
				var col = (!isNaN(parseInt(i.substring(1)))) ? i.substring(0,1) : i.substring(0,2);
				var row = (!isNaN(parseInt(i.substring(1)))) ? parseInt(i.substring(1)) : parseInt(i.substring(2));
				var value = grossPayoutSheet[i].v;
				if (row === 2) {
					var value = grossPayoutSheet[i].v;
					headers[col] = value.trim();
					continue;
				}
				if (row !== 1 && !data[row]) {
					data[row] = {};
				} else if (row !== 1){
					data[row][headers[col]] = value;
				}
			}

the value in the cell B3 is

05/07/2017

but after parsing the value is

B3: { t: 'n', v: 42921, w: '42921' }

I want the date in string format that is I want to change the cell format from 'n' to 's'

Can anyone please me out with this?

like image 766
Piyush Kumar Avatar asked Jul 07 '17 09:07

Piyush Kumar


2 Answers

 const workbook = excel.readFile(file.path);

 const sheet_name_list = workbook.SheetNames;
 const json = excel.utils.sheet_to_json(workbook.Sheets[sheet_name_list[0]], {
  raw: false,
 });
like image 190
Ashish Avatar answered Sep 25 '22 01:09

Ashish


var workbook = XLSX.read(data, {
  type: 'binary',
  cellDates: true,
  cellNF: false,
  cellText: false
});
like image 25
Manjunath Avatar answered Sep 23 '22 01:09

Manjunath