maven 引入 <dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>3.0.5</version> </dependency> 创建导出对象 @Data public class ExportModel { /** * vlaue: 表头名称 * index: 列的号,0为第一列 */ //order @ExcelProperty(value = "单号", index = 0) private String no; @ExcelProperty(value = "名称", index = 1) private String name; } ExcelWriter writer = EasyExcel.write(filePath).build(); WriteSheet sheet = EasyExcel.writerSheet("导出文件").head(ExportModel.class).build();
可以循环
for(int i=0;i<num;i++){
writer.write(data(), sheet);
}
最后
writer.finish();