question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

It's not possible to send a large XLS file using a stream writter

See original GitHub issue

Hello!

I’m trying to send a large XLS document using WorkbookWriter over HTTP.

Expected: Receiving file, chunk by chunk. File should be OK.

Actual: Chrome shows “Starting - 0 B/s - 0 B” about a minute, then I get “Failed - Network error”.

Info: It works good with small data amount.

Please, check the code sample below.

'use strict';

const Excel = require('exceljs');
const http = require('http');
const async = require('async');

http.createServer((request, response) => {

    let workbook = new Excel.stream.xlsx.WorkbookWriter({
        stream: response
    });

    let worksheet = workbook.addWorksheet('work-sheet');

    worksheet.columns = [{header: 'field', key: 'field'}];

    response.writeHead(200, {
        'Content-Disposition': `attachment; filename="export.xlsx"`,
        'Transfer-Encoding': 'chunked',
        'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    });

    let count = 0;

    async.whilst(() => {

        return count < 1000;

    }, callback => {

        count++;

        console.log(`Write row ${count}`);

        worksheet.addRow({field: 'test'}).commit();

        setTimeout(() => {
            callback(null, count);
        }, 1000);

    }, (err, n) => {

        workbook.commit().then(() => {

            console.log('done');
        });
    });

}).listen(2000);

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:3
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
bushevcommented, Jan 16, 2018
0reactions
hsb0818commented, Jul 22, 2021

Did you guys figure this out? In my case as well, download does not begin and only after the file is fully generated the download happens in an instant. So it is almost like the streaming interface does not stream 😉

I do have commit() sprinkled on every possible place as well.

is this issue solved? my program work like this…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem when using a StreamWriter for writing very large files.
This works fine for most of the data. There is one table that generated a very large flat file (over 18gig). The data...
Read more >
c# - Stream out large datatable to excel file - Stack Overflow
You run out of memory because the whole table is written to memory first regardless if the StreamWriter is flushed or not before...
Read more >
Stream in C# Tutorial: StreamReader & StreamWriter [Example]
This tutorial covers basic to the advanced topic on C# Stream. Learn StreamReader and StreamWriter with detailed code examples.
Read more >
Reading and writing to file - PhpSpreadsheet Documentation
A typical use of this feature is when you need to read files uploaded by your users, and you don't know whether they...
Read more >
How read/write Excel file in chunks or without loading ... - Reddit
As others have mentioned, Excel files (either xls or xlsx) are virtual filesystems (zipped) and not designed for streaming record by record.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found