今天导出数据,查询的数据量是 共110959条记录。但是excel导出确实10万。
一开始怀疑是xls导致的,切换成xlsx发现问题依然存在。
03版本默认6W行,07默认100W
如果不是excel问题,只能是代码问题,于是打开easypoi源码
public Workbook exportBigExcel(IExcelExportServer server, Object queryParams) {
int page = 1;
List<Object> list = server
.selectListForExcelExport(queryParams, page++);
while (list != null && list.size() > 0) {
//填充到excel
appendData(list);
//分页查询
list = server.selectListForExcelExport(queryParams, page++);
}
return closeExportBigExcel();
}
在自己写的实体类上打印页码,发现有223页。
2023-06-27 13:52:26.561 [edu-admin-async-1] INFO c.i.e.a.e.s.i.AttendanceAdministrationExportServiceImpl [?:?] [] - 当前页码223
如果查询没有问题,那么就在填充上出现问题
public Workbook appendData(Collection<?> dataSet) {
if (sheet.getLastRowNum() + dataSet.size() > entity.getMaxNum()) {
sheet = workbook.createSheet();
index = 0;
}
Iterator<?> its = dataSet.iterator();
while (its.hasNext()) {
Object t = its.next();
try {
index += createCells(patriarch, index, t, excelParams, sheet, workbook, rowHeight, 0)[0];
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
throw new ExcelExportException(ExcelExportEnum.EXPORT_ERROR, e);
}
}
return workbook;
}
debug发现entity.getMaxNum()为10W
那这个数据是哪里来的呢
在setMaxNum处debug
public void init(ExportParams entity, List<ExcelExportEntity> excelParams) {
LOGGER.debug("ExcelBatchExportServer only support SXSSFWorkbook");
entity.setType(ExcelType.XSSF);
workbook = new SXSSFWorkbook();
this.entity = entity;
this.excelParams = excelParams;
super.type = entity.getType();
createSheet(workbook, entity, excelParams);
if (entity.getMaxNum() == 0) {
entity.setMaxNum(USE_SXSSF_LIMIT);
}
insertDataToSheet(workbook, entity, excelParams, null, sheet);
}
如果maxNum为0那么设置为10W。
自此问题解决,手动设置maxNum即可