<Button
type={"primary"}
key="out"
onClick={async ()=>{
const ExportJsonExcel = require("js-export-excel");
const datas = selectedRowsState //确保勾到的数据是一个列表,列表中每个值是字典
const option = {};
const dataTable = []
if(datas){
for (const i in datas){
console.log("datas[i]",datas[i])
const obj = {
'gxdwbmjm':datas[i].gxdwbmjm,
'lg_num':datas[i].lg_num,
'fj_num':datas[i].fj_num,
'cw_num':datas[i].cw_num,
'ruzhu_num':datas[i].ruzhu_num,
'zaizhu_num':datas[i].zaizhu_num,
'ruzhu_rate':datas[i].ruzhu_rate,
}
dataTable.push(obj)
}
}
option.fileName = "统计结果";
option.datas = [
{
sheetData: dataTable,
sheetName: "sheet",
sheetFilter: ["gxdwbmjm","lg_num","fj_num", "cw_num","ruzhu_num","zaizhu_num","ruzhu_rate"],
sheetHeader: ["地区","旅馆家数","房间数", "床位数","入住总人次","在住人数","入住率"],
columnWidths: [10,10,10,10,10,10,10],
}
];
const toExcel = new ExportJsonExcel(option); //new
toExcel.saveExcel(); //保存
}}
>批量导出<DownOutlined/></Button>
当然使用之前需要安装js-export-excel才行,cmd去项目根目录执行命令安装:yarn add js-export-excel
js下载excel示例demo
John.liu_Test2024-11-08 22:05