关于javascript:前端导出excel代码

// res为后端传递的数据
const blob = new Blob([res], {
          type: "application/ms-excel",
        });
        const elink = document.createElement("a");
        elink.download = "文件名.xls";
        elink.style.display = "none";
        elink.href = URL.createObjectURL(blob);
        document.body.appendChild(elink);
        elink.click();
        URL.revokeObjectURL(elink.href); // 开释URL对象
        document.body.removeChild(elink);

发送申请时须要设置responseType: ‘blob’, 不然关上的excel会有乱码

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理