赛778 2023-07-06 10:24 采纳率: 0%
浏览 11

关于#excel#的问题,如何解决?

Vue3 导出文件为excel 代码如下:
export function excel(code,total,name,upInfo) {

axios({
    url: "/report/bb/exportExcel",
    method: "post",
    data: {
        csbs: code,
        pageIndex: 1,
        pageSize: total,
        parameterMap:    JSON.stringify(deleteKey(upInfo))
    },
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    responseType: "blob"
}).then(res => {
    const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' });
    const fileName = name
    if ('download' in document.createElement('a')) { // 不是IE浏览器
        const url = window.URL.createObjectURL(blob);
        const link = document.createElement('a');
        link.style.display = 'none';
        link.href = url;
        link.setAttribute('download', fileName);
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link); // 下载完成移除元素
        window.URL.revokeObjectURL(url); // 释放掉blob对象
    } else { // IE 10+
        window.navigator.msSaveBlob(blob, fileName);
    }
})

}

同样的代码 只有一个页面导出不带表头

img

这个页面带表头

img

两个是同样的页面 不同路由

  • 写回答

2条回答 默认 最新

  • 念九_ysl 2023-07-06 10:59
    关注

    有没有可能是接口返回的数据问题

    评论

报告相同问题?

问题事件

  • 修改了问题 7月6日
  • 创建了问题 7月6日