excel文件下载下来损坏 js_js处理文件流下载excel
this.requestUp.post(this.APIS.UPLOADFORM,?formData,{?responseType:?"blob"}).then(res?=>?{
console.log('UPLOADFORM',?res)
if(res.type?==?'application/json'){
this.fileList?=?[]
this.batchImportBox?=?false
this.resetList()
}else{
//?下載失敗文件
function?downloadFile(data,?fileName)?{
let?blob?=?new?Blob([data],?{type:?`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8`});
//?獲取heads中的filename文件名
let?downloadElement?=?document.createElement('a');
//?創建下載的鏈接
let?href?=?window.URL.createObjectURL(blob);
downloadElement.href?=?href;
//?下載后文件名
downloadElement.download?=?fileName;
document.body.appendChild(downloadElement);
//?點擊下載
downloadElement.click();
//?下載完成移除元素
document.body.removeChild(downloadElement);
//?釋放掉blob對象
window.URL.revokeObjectURL(href);
}
downloadFile(res,'物料導出錯誤數據表')
}
})
總結
以上是生活随笔為你收集整理的excel文件下载下来损坏 js_js处理文件流下载excel的全部內容,希望文章能夠幫你解決所遇到的問題。

- 上一篇: c++ 一个函数包括多个返回值判断_轻松
- 下一篇: python中change是什么意思_C