![](/img/trans.png)
[英]xlsx file corrupted while downloading with the file-saver npm package
[英]XLSX file corrupted while downloading using vue js and axios
您好,我正在嘗試使用 axios 為 excel 文件創建下載,但我無法下載並打開它,您能幫我看看有什么問題嗎?
const blob = new Blob([result.data], { type: 'application/vnd.ms-excel' });
const url = URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.setAttribute('download', 'atetes.xlsx')
document.body.appendChild(link)
link.click()
我嘗試了很多解決方案,但我總是得到一個損壞的文件
我也面臨同樣的問題並花了足夠的時間,原因你會注意到響應 object 包含無效的數據,因此前端解析出錯了,所以在我的情況下,解決方案非常簡單。 在進行 API 調用時,我添加了responseType作為數組緩沖區以使其工作:
return await client({ method: "get", url: `[YOUR API ENDPOINT]`,
responseType: "arraybuffer",
headers: {
"Authorization": token,
"Accept": "application/octet-stream",
}});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.