封装下载Blob类型的excel方法 导出excel 下载excel
【代码】封装下载Blob类型的excel方法 导出excel 下载excel。
·
废话不多说直接上代码
function downloadExcel(obj, name) {
const blob = new Blob([obj], {
type: "application/vnd.ms-excel,charset=utf-8",
});
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.style.display = "none";
link.href = url;
const today = new Date().toLocaleDateString().split("/").join("-");
const fileName = name + "-" + today;
link.setAttribute("download", fileName);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
更多推荐
所有评论(0)