0

I'm using ExcelJs in my Angular 7 app, where I have a function to import excel file. The problem is when I console.log the data from the worksheet the date formats are wrong for e.g. the cell contains 2021.11.30 12:00:00 but in the log it shows 44530.5.

here is the code for importing the file:

    let workBook = null;
    let jsonData = null;
    const reader = new FileReader();
    const file = ev.target.files[0];
    reader.onload = (event) => {
      const data = reader.result;
      workBook = XLSX.read(data, { type: 'binary' });
      jsonData = workBook.SheetNames.reduce((initial, name) => {
        const sheet = workBook.Sheets[name];
        initial[name] = XLSX.utils.sheet_to_json(sheet);
        return initial;
      }, {});
      const dataString = JSON.stringify(jsonData);
      console.log('data: ', dataString);  <-- this shows the data from worksheet
      document.getElementById('output').innerHTML = dataString.slice(0, 30000).concat("....");
      // this.setDownload(dataString);
    }
    reader.readAsBinaryString(file);
  }

In the worksheet the cell is set to Date. Any ideas what can I do to fix the issue with the wrong date format?

Kerk
  • 283
  • 1
  • 4
  • 24
  • Does this answer your question? [Converting Excel Date Serial Number to Date using Javascript](https://stackoverflow.com/questions/16229494/converting-excel-date-serial-number-to-date-using-javascript) – Engam Jan 03 '22 at 14:20
  • 1
    excel actually stores dates as a number, and just formats it to make it look nice. So when you import a excel file with dates, you get the number, and have to convert it to javascript format. Take a look at the link above, I think that will help you :) – Engam Jan 03 '22 at 14:23
  • thanks I'll take a look – Kerk Jan 03 '22 at 14:31

0 Answers0