导出数据excel打开失败,为什么无法导出excel

首页 > 实用技巧 > 作者:YD1662023-05-05 12:27:30

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)

栏目热文

文档排行

本站推荐

Copyright © 2018 - 2021 www.yd166.com., All Rights Reserved.