先贴代码
for(int i = 0;i<=totalPage;i++){ queryMap.put("startIndex", i+1); list = sRealTankRecMapper.getSRealTankRecList(queryMap); WriteSheet writeSheet = EasyExcel.writerSheet(i,"合同"+(i+1)).head(clazz).build(); excelWriter.write(list,writeSheet);
excelWriter.finish();
}
首先排除了sheet页的号数i和sheet的名称是不一致的,测如果名称一直的话,就算i不一样,也只会生成一个sheet页。排除后发现还是只生成了一个,最后猜测可能是excelWriter.finish()方法刷新的问题,改动一下
for(int i = 0;i<=totalPage;i++){ queryMap.put("startIndex", i+1); list = sRealTankRecMapper.getSRealTankRecList(queryMap); WriteSheet writeSheet = EasyExcel.writerSheet(i,"合同"+(i+1)).head(clazz).build(); excelWriter.write(list,writeSheet); } excelWriter.finish();
测试,成功
好像是因为finish()代表整个Excel文件写数据结束,所以要先填充完sheet的数据,再finish()就好了