Skip to content

Stream xlsx return a corrupted file [Excel js 4.2.0] #1594

@Djcharles26

Description

@Djcharles26

I have a code in which i create a pretty big xlsx, for that I needed to use stream function, avoiding heap memory errors, everything worked fine on local environment, but in the moment I passed to a server, the stream files always returns a corrupted file, which I can only open in Excel with the repair tool, and that doesn't work every time.
At the same time, if the file is created with xlsx.writeFile(); it can be opened correctly.
My server specs are:

OS: Ubuntu 20.04 LTS

RAM: 8 Gb

Code:

        let min = new Date(date.min);
        let max = new Date(date.max);
        const dir = `/home/data/uploads/reports/${req.user._id}/`;
        if(!fs.existsSync(dir))shelljs.mkdir("-p", dir);
        const filename = `report-${(new Date().getTime())}.xlsx`;
        const file = `${dir}/${filename}`;
        const stream = fs.createWriteStream(file);
        const options = {
            stream: stream,
            useStyles: true,
        };

        const workbook = new Exceljs.stream.xlsx.WorkbookWriter(options);
        const sheet = workbook.addWorksheet("reports");
       // process here (committing every row I create)
       // then committing the unique sheet I need
       sheet.commit();
       await workbook.commit();

Please help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions