前端导出excel
首先
import XLSX from "xlsx";
然后
const btnTo = () => {
const a = tableData.value?.map((item) => {
return [item.name, item.name2, item.name3;
});
const filename = "人员名单.xlsx"; //文件名称
const data = [["字段名1", "字段名2", "字段名3"], ...a]; //数据是二维数组
const ws_name = "Sheet1"; //第一个sheet的名称
const wb = XLSX.utils.book_new(),
ws = XLSX.utils.aoa_to_sheet(data);
XLSX.utils.book_append_sheet(wb, ws, ws_name); //将数据添加到工作薄
XLSX.writeFile(wb, filename); //导出Excel
};