给项目引入依赖
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>3.2.0</version>
</dependency>
多sheet页导出
private static List<Title> cleaData = Lists.newArrayList();
private static List<Title> orderData = Lists.newArrayList();
private static List<Title> total = Lists.newArrayList();
@SneakyThrows
private static void reportExcel(String path) {
Workbook workbook = new HSSFWorkbook();
ExportParams exportParams0 = new ExportParams();
exportParams0.setSheetName("汇总");
ExportParams exportParams1 = new ExportParams();
exportParams1.setSheetName("删除明细");
ExportParams exportParams2 = new ExportParams();
exportParams2.setSheetName("增加明细");
ExcelExportService service0 = new ExcelExportService();
service0.createSheet(workbook, exportParams0, Title.class, total);
ExcelExportService service1 = new ExcelExportService();
service1.createSheet(workbook, exportParams1, Title.class, cleaData);
ExcelExportService service2 = new ExcelExportService();
service2.createSheet(workbook, exportParams2, Title.class, orderData);
FileOutputStream fos = new FileOutputStream(path);
workbook.write(fos);
fos.close();
}
@Data
@Builder
class Title {
@Excel(name = "企业代码")
private String spCode;
@Excel(name = "业务代码", width = 20)
private String serviceCode;
@Excel(name = "业务名称", width = 30)
private String serviceName;
@Excel(name = "价格")
private String price;
@Excel(name = "省公司")
private String provinceName;
private String provinceId;
@Excel(name = "需清理")
private String cleanNum;
@Excel(name = "需增加")
private String orderNum;
}