//利用easyexcel实现用某个模板的多sheet页写入不同类的查询结果,以下的data()众方法是获取数据用的,仅为举例
ExcelWriter excelWriter = null;
try {
String templateFileName = "D:\\360安全浏览器下载\\m31f01_job_pack_demo\\job_define.xlsm";
String fileName = "D:\\360安全浏览器下载\\m31f01_job_pack_demo\\test1.xlsm";
//1、指定模板和要写出的文件
excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build();
//2、每个sheet页指定对应类的head,由于使用了模板的表头,因此neadHead就false,不再使用类里的字段标头
WriteSheet writeSheet1 = EasyExcel.writerSheet(1).head(Ac3SyncGroup.class).needHead(false).build();
//3、挨个把每个类的数据写入到对应sheet页中,sheet()中可写sheet页下标或者名称,也可以都写
excelWriter.write(data(), writeSheet1);
WriteSheet writeSheet2 = EasyExcel.writerSheet(3).head(Ac3JobGroup.class).needHead(false).build();
excelWriter.write(data2(), writeSheet2);
WriteSheet writeSheet3 = EasyExcel.writerSheet(4).head(Ac3Job.class).needHead(false).build();
excelWriter.write(data3(), writeSheet3);
WriteSheet writeSheet4 = EasyExcel.writerSheet(5).head(Ac3JobStep.class).needHead(false).build();
excelWriter.write(data4(), writeSheet4);
WriteSheet writeSheet5 = EasyExcel.writerSheet(8).head(Ac3JobRela.class).needHead(false).build();
excelWriter.write(data5(), writeSheet5);
} catch (Exception e) {
e.printStackTrace();
}finally {
// 千万别忘记finish 会帮忙关闭流
if (excelWriter != null) {
excelWriter.finish();
}
}
easyexcel用模板实现多sheet页导出不同类的查询结果
最新推荐文章于 2024-07-04 17:06:55 发布