excel4node icon indicating copy to clipboard operation
excel4node copied to clipboard

Force Browser to download excel file

Open sandysh opened this issue 5 years ago • 4 comments

Hello Team, thank you for the awesome package you have created. I have only one query regarding this package and that is if there is a way to force open a save dialog in browser instead of saving excel file directly in current working directory. The scenario is that i want user to choose location to where they want to download the excel file.

sandysh avatar Feb 10 '20 16:02 sandysh

workbook.writeToBuffer().then((buffer) => {
    const binaryBuffer = Buffer.from(buffer);
    res.attachment('Spreadsheet.xlsx');
    return res.send(binaryBuffer);
});

raul3k avatar May 08 '20 21:05 raul3k

hello, I tried this solution but I didn't get the download message on the cllient. what could I be missing? I am using angularjs. This is the call to the server:

$scope.createReport = function(){ $http.post('/export/createHoursReport?'+ $.param({campaign : campaign_id, date : $('#date').val(), type: 'hours'})) .success(function(data) { console.log(data); }) }

I am guessing I am missing how to process the file. Can someone help me?

AutomataVM avatar Sep 18 '20 20:09 AutomataVM

tried processing it as blob data, but the file in result is corrupted. What could I be missing?

var blob = new Blob([data], { type: "octet/stream" }); var link = document.createElement('a'); link.href = window.URL.createObjectURL(blob); link.download = 'filename.xlsx'; document.body.appendChild(link); link.click(); document.body.removeChild(link);

AutomataVM avatar Sep 18 '20 20:09 AutomataVM

tried processing it as blob data, but the file in result is corrupted. What could I be missing?

var blob = new Blob([data], { type: "octet/stream" }); var link = document.createElement('a'); link.href = window.URL.createObjectURL(blob); link.download = 'filename.xlsx'; document.body.appendChild(link); link.click(); document.body.removeChild(link);

Did you figure out? In postman I can save response, but unable to do it on client side of browser

ikochetkov avatar Apr 17 '21 07:04 ikochetkov