tft每日頭條

 > 科技

 > 為什麼excel導出出錯

為什麼excel導出出錯

科技 更新时间:2024-11-30 06:20:56

responsetype: "arraybuffer" 是關鍵

export function filePost(url, params, config) { let userAuth = JSON.parse(sessionStorage.getItem("userAuth")); return new Promise((resolve, reject) => { axios.create({ baseURL: baseUrl, timeout: 15000, headers: { "Content-Type": "application/json-patch json", "Authorization": userAuth.token_type " " userAuth.access_token, }, responseType: "arraybuffer" //必須設置,不然導出的文件無法打開 }) .post(url, params, config) .then(res => { resolve(res); }) .catch(err => { reject(err); }); }); }

為什麼excel導出出錯(文件流導出為excel無法打開的問題)1

導出接口:​​

const exportExl = () => { store .exportExl({ shop: 'shopNumber,shopName,road,shopAddress', shopNumber: 'S000075,S000002,S000077', }) .then((res) => { const blob = new Blob([res], { type: 'application/vnd.ms-excel;charset=utf-8', }) const fileName = '部隊信息.xlsx' const elink = document.createElement('a') elink.download = fileName elink.style.display = 'none' elink.href = URL.createObjectURL(blob) document.body.appendChild(elink) elink.click() URL.revokeObjectURL(elink.href) // 釋放URL 對象 document.body.removeChild(elink) }) }

為什麼excel導出出錯(文件流導出為excel無法打開的問題)2

,

更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!

查看全部

相关科技资讯推荐

热门科技资讯推荐

网友关注

Copyright 2023-2024 - www.tftnews.com All Rights Reserved