Open nvcken opened 10 years ago
try
window.open(replaceWithYourUrl);
On Mon, Sep 29, 2014 at 4:49 AM, nvcken notifications@github.com wrote:
My server code var file = fs.readFileSync('./res_report/output/out.xlsx', 'binary'); res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); res.setHeader('Content-Disposition', "attachment; filename=" + "out.xlsx") res.end(file, 'binary'); How client javascript download excel file
— Reply to this email directly or view it on GitHub https://github.com/functionscope/Node-Excel-Export/issues/20.
@functionscope var file = fs.readFileSync('./res_report/output/out.xlsx', 'binary'); res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); res.setHeader('Content-Disposition', "attachment; filename=" + "out.xlsx") res.end(file, 'binary'); client I use POST method request to server and server response by above server code My client code angularjs $http.post('/abc/excel', post).success(function(data){ var blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }); var objectUrl = URL.createObjectURL(blob); window.open(objectUrl); }) .error(function( data){ })
but not work, file open corrupt. What I am wrong
If I do the same with csv file it work
check out this link
On Sep 29, 2014 7:57 AM, "nvcken" notifications@github.com wrote:
If I do the same with csv file it work
— Reply to this email directly or view it on GitHub.
Hi, Me also meet this issue after spent long time I found solution, It is working for me.
setup's
1.convert your file as base64 string and send as response
EXAMPLE:
var result = nodeExcel.execute(conf);
return res.status(200).send(new Buffer(result.toString(), 'binary').toString('base64'));
2.client side decodebase64 string, make as blob and create url from blob
EXAMPLE:
var contentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
var sliceSize = sliceSize || 512;
var byteCharacters = atob(data);
var byteArrays = [];
for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
var slice = byteCharacters.slice(offset, offset + sliceSize);
var byteNumbers = new Array(slice.length);
for (var i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
var blob = new Blob(byteArrays, {type: contentType});
var blobUrl = URL.createObjectURL(blob);
window.location = blobUrl;
Enjoy
My server code var file = fs.readFileSync('./res_report/output/out.xlsx', 'binary'); res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); res.setHeader('Content-Disposition', "attachment; filename=" + "out.xlsx") res.end(file, 'binary'); How client javascript download excel file