WriteSheet writeSheet = EasyExcel.writerSheet("Sheet").build();
// 写入数据
try (ExcelWriter excelWriter = EasyExcel.write(xlsxFileName, exportResultVO.getClass())
.registerWriteHandler(new FillHeadMergeStrategy())
.includeColumnFieldNames(includeColumnFieldNames)
.build()) {
// 分页查询
for (int j = 0; j <= MAX_COUNT; j++) {
long start1 = System.currentTimeMillis();
List<?> result = function.apply(maxId);
long end1 = System.currentTimeMillis();
log.info("function.apply end:" + (end1 - start1));
if (CollectionUtils.isEmpty(result)) {
// 防止创建excel报错
excelWriter.write(result, writeSheet);
break;
}
// 写入excel
long start2 = System.currentTimeMillis();
excelWriter.write(result, writeSheet);
long end2 = System.currentTimeMillis();
log.info("excelWriter.write end:" + (end2 - start2));
maxId = getMaxId(maxId, result);
result.clear();
}
}
问题描述
大批量导出大概100万数据,每次写入10000数据,开始写入的时候也很快,监控了 excelWriter.write(result, writeSheet),发现在写入几十万数据之后,这个方法写入数据很慢,大概8s左右