首页
/
每日頭條
/
科技
/
為什麼excel導出出錯
為什麼excel導出出錯
更新时间:2024-04-28 17:32:17

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

,
Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
Copyright 2023-2024 - www.tftnews.com All Rights Reserved