废话不多说直接上代码
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);
}