node.js - download binary excel response from nodejs in angular 2 -
am new angular 2 , having difficulties downloading xlsx file api(node). have gone through discussion issues can't seem figure going wrong.
this have done .
node api
res.setheader('content-type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); res.setheader("content-disposition", "attachment; filename=" + filename+".xlsx"); workbook.xlsx.write(res) .then(function() { res.end(); });
angular 2 post request
let bodystring = json.stringify(body); let headers = new headers( { 'content-type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' , 'x-access-token':localstorage.getitem('auth_token') , 'accept': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', }); let options = new requestoptions({ headers: headers, responsetype: responsecontenttype.arraybuffer}); return this.http .post(`${this.reportsurl}/print`, bodystring, options) .map((res)=>{ console.log(res.arraybuffer()) var blob = new blob([res], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }); var objecturl = url.createobjecturl(blob); window.open(objecturl); });
i have tried several methods mentioned in stackoverflow , github none has helped. result getting [excel output][1]
[1]: https://i.stack.imgur.com/oc5gk.png . if use postman it's working required. please help.
Comments
Post a Comment