Home > Back-end >  Unable to DATE VALUE using XLSX Library Javascript
Unable to DATE VALUE using XLSX Library Javascript

Time:08-26

I need to separate all the headers of Excel sheet. code that i implemented is working but only text format is working. kindly help.

const xlsx = require('xlsx');

const workbook = xlsx.readFile('./SMALL.xlsx');
const worksheet = workbook.Sheets[workbook.SheetNames[0]];

const workbookHeaders = xlsx.readFile('./SMALL.xlsx', { sheetRows: 1 });
const columnsArray = xlsx.utils.sheet_to_json(workbookHeaders.Sheets[workbook.SheetNames[0]], { header: 1 })[0];


console.log(columnsArray);

Response

My console should print ['Task', '1/2022', '2/2022' ]. instead its printing [ 'Task', 44562, 44593 ]

Image of console/node output and spreadsheet cells

CodePudding user response:

Looks like you can specify a date format string in the options parameter to the sheet_to_json(worksheet, opts) method.

The option property name appears to be: dateNF

https://www.npmjs.com/package/xlsx#parsing-options

  • Related