h5 json 生成excel
引入库文件
创建下载按钮
实现转换
var data = [
["Joa Doe", "joa@doe.com"],
["Job Doe", "job@doe.com"],
["Joe Doe", "joe@doe.com"],
["Jon Doe", "jon@doe.com"],
["Joy Doe", "joy@doe.com"]
];
var workbook = XLSX.utils.book_new(),
worksheet = XLSX.utils.aoa_to_sheet(data);
workbook.SheetNames.push("First");
workbook.Sheets["First"] = worksheet;
res = XLSX.writeFile(workbook, "demo.xlsx");
下载文件
方式一: 库文件
window.saveAs(new Blob([wbout], { type: "application/octet-stream" }));
方式二: a 标签
onst link = document.createElement('a');
let blob = new Blob([res], {type: 'application/vnd.ms-excel'});
link.style.display = 'none';
link.href = URL.createObjectURL(blob);
link.download = "demo.xlsx";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
本文来自博客园,作者:vx_guanchaoguo0,转载请注明原文链接:https://www.cnblogs.com/guanchaoguo/p/17140413.html