6

Using excel4node I am able to write the file to the harddrive. But rather I would like to return it as a download without saving the file on the server. I think the following code is required, but unsure how to use it:

wb.writeToBuffer().then(function(buffer) {
  console.log(buffer);
});

Does anyone have an idea on this?

xfscrypt
  • 16
  • 5
  • 28
  • 59

3 Answers3

5

Here is an example with nodeJS/Express GET Request. Is this what you're looking for ?

var xl = require('excel4node');

router.route("/test/").get((req, res) => {
    var wb = new xl.Workbook();
    var ws = wb.addWorksheet('SHEET_NAME');
    ws.cell(1, 1).string('ALL YOUR EXCEL SHEET FILE CONTENT');
    wb.write(`FileName.xlsx`, res);

});
Shubh Patel
  • 51
  • 1
  • 4
2
let binarybuffer = new Buffer(buffer, 'binary');
res.attachment('filename.xlsx'); 
return res.send(binarybuffer);
viveksharma
  • 557
  • 4
  • 9
0

//front-end react --

var fileDownload = require('js-file-download');  //npm i js-file-download
    axios({
        url:url,
        method: 'GET',
        responseType: 'blob', // Important
    }).then((response) => {
        fileDownload(response.data, `FileName.xlsx`);
    });
teehid
  • 9
  • 2