0
私は角度2でapi呼び出しの応答から'xlsx 'ファイルをダウンロードしようとしています。応答本体で、データをxml形式で取得しています。ダウンロード中ですが、ファイルを開いた後に破損したファイルのようなエラーが表示されます。以下のサンプルコードをご覧ください。 response._body
で角度2のAPIコールの応答で.xlsxファイルをダウンロードできませんか?
this.homeDetailViewService.downloadReport(JSON.stringify(requestBody))
.subscribe((response) => {
if (response) {
console.log(response);
var contentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
let blob = new Blob([response._body],{type:contentType});
let link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = "report.xlsx";
link.click();
}
},
(error) => {
let errorObj = JSON.parse(error);
// If theres no data then reset the model list and total
if (errorObj.status === "error" && errorObj.message.match(/Record not found/)) {
this.curData = null;
}
this.loadingAnimation = false; // error path
this.handleError(error);
},
() => {// onComplete
});
は、だから私は '.xlsxの' 形式にXML型のレスポンスボディをダウンロードする方法がわからない
の下のようなデータを取得しています。