//下载 xlsx 和file-saver两个包
//组件中引入
import XLXS from "xlsx";
import FileSaver from "file-saver";
const exportClick = () => {
// 导出文件名
const filename = "导出.xlsx";
// 导出表格加id,通过id获取要导出的表单
const a= XLXS.utils.table_to_book(document.getElementById("table"));
const b = XLXS.write(a, {
bookType: "xlsx",
bookSST: true,
type: "array",
});
try {
FileSaver.saveAs(
new Blob([b], {
type: "application/octet-stream",
}),
filename
);
} catch (e) {
console.log(e);
}
return b;
};
纯前端导出excel(vue3)
最新推荐文章于 2024-05-24 19:09:11 发布