Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
        });
like image 338
kevin seda Avatar asked Jul 26 '26 02:07

kevin seda


1 Answers

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

like image 81
traynor Avatar answered Jul 28 '26 15:07

traynor