node.jsexcelexceljs

Can I avoid exceljs date formatting


I'm having an issue where if I try to read a row that was originally a date, it gets converted to a number like : Last_Contact_Date: 45618 from the original 31/05/2024 in the file. Can this somehow be prevented and if not can you recommend a library to convert it to a proper date.

My worksheet is configured as follows:

const workbookReader = new ExcelJS.stream.xlsx.WorkbookReader(
    tempFilePath,
    {
        sharedStrings: "cache",
        worksheets: "emit",
    }
);

And here I'm reading the values:

        worksheet.on("row", async row => {
            //Date values are numbers
            const values = row.values.slice(1);
        });

Solution

  • Try adding styles: "cache" to the options:

    const workbookReader = new ExcelJS.stream.xlsx.WorkbookReader(
        tempFilePath,
        {
            sharedStrings: "cache",
            worksheets: "emit",
            styles: "cache",
        }
    );
    

    it seems there's some problem with styles, see: [BUG] date parsing doesn't work in streaming mode #1430