Search code examples
angulartypescriptxlsxangular7sheetjs

SheetJs converting date automatically angular 7


I'm using sheetjs in angular 7. And I'm exporting excel from my json. But excel converting my date to 02/29/2019 format. But, I'm sending "29.02.2019". I'm sending as string, excel still converting. I also send "29.02.2019." by adding "." character at end of date, but it still convert to "02/29/2019." . How can I achieve showing by my format?

import * as XLSX from 'xlsx';

exportExcelFromJson(jsonData): void {
    const ws: XLSX.WorkSheet = XLSX.utils.json_to_sheet(jsonData);
    const wb: XLSX.WorkBook = XLSX.utils.book_new();

    XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
    XLSX.writeFile(wb, 'MyExcel.xlsx');
}

Solution

  • Add the dateNF option to your call as described in the documentation: https://docs.sheetjs.com/#array-of-objects-input

    so such a call should work:

    const ws: XLSX.WorkSheet = XLSX.utils.json_to_sheet(jsonData, {dateNF:"dd.MM.yyyy"});