Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.8K
Vistas
Date in XLSX file not parsing correctly in SheetJs

I am trying to read a XLSX file using sheetjs node-module with a column having dates. After parsing I got data in incorrect format

File data is : 2/17/2020

But after xlsx read it gives me 2/17/20. It is changing the year format. My requirement is to get the data as it is.

Sample Code:

var workbook = XLSX.readFile('a.xlsx', {
  sheetRows: 10
});
    
var data = XLSX.utils.sheet_to_json(workbook.Sheets['Sheet1'], {
  header: 1,
  defval: '',
  blankrows: true,
  raw: false
});
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

There's a solution presented here using streams but can equally work with readFile. The problem that was at play in the issue is that the value for the dateNF option in sheet_to_json needs some escape characters.

E.g.:

const XLSX = require('xlsx');
const filename = './Book4.xlsx';

const readOpts = { // <--- need these settings in readFile options
  cellText:false, 
  cellDates:true
};

const jsonOpts = {
  header: 1,
  defval: '',
  blankrows: true,
  raw: false,
  dateNF: 'd"/"m"/"yyyy' // <--- need dateNF in sheet_to_json options (note the escape chars)
}

const workbook = XLSX.readFile(filename, readOpts);
const worksheet = workbook.Sheets['Sheet1'];
const json = XLSX.utils.sheet_to_json(worksheet, jsonOpts);

console.log(json);

For this input:

enter image description here

Will output:

[
  [ 'v1', 'v2', 'today', 'formatted' ],
  [ '1', 'a', '14/8/2021', '14/8/2021' ]
]

Without the dateNF: 'd"/"m","/yyyy' you get same problem as you describe in the question:

[
  [ 'v1', 'v2', 'today', 'formatted' ],
  [ '1', 'a', '8/14/21', '8/14/21' ]
]

The two potential unwanted side effects are:

  1. use of the cellText and cellDates options in readFile
  2. note my custom format of yyyy^mmm^dd in the input - the dateNF setting overrides any custom setting
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda