natergj / excel4node

Node module to allow for easy Excel file creation
MIT License
1.38k stars 215 forks source link

Force Browser to download excel file #309

Open sandysh opened 4 years ago

sandysh commented 4 years ago

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.

raul3k commented 4 years ago
workbook.writeToBuffer().then((buffer) => {
    const binaryBuffer = Buffer.from(buffer);
    res.attachment('Spreadsheet.xlsx');
    return res.send(binaryBuffer);
});
AutomataVM commented 4 years ago

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 commented 4 years ago

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);

ikochetkov commented 3 years ago

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