使用SXSSFWorkbook 进行百万数据导出,测试结果为一百万数据在自己电脑导出需要 26t秒左右,
同样的数据使用python导出需要22秒左右
添加依赖:
<!--自行补充添加的poi-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
导出操作的代码:
public static void main(String[] args) throws Throwable {
long benginTime = System.currentTimeMillis();
System.out.print("开始时间:"+benginTime);
// 执行代码
SXSSFWorkbook wb = new SXSSFWorkbook(100);
Sheet sh = wb.createSheet("sheet1");
for(int rownum = 0; rownum < 1000000; rownum++){
Row row = sh.createRow(rownum);
for(int cellnum = 0; cellnum < 10; cellnum++){
Cell cell = row.createCell(cellnum);
String address = new CellReference(cell).formatAsString();
cell.setCellValue(address);
}
}
FileOutputStream out = new FileOutputStream("d:/export.xlsx");
wb.write(out);
out.close();
wb.dispose();
// 注释
long endTime = System.currentTimeMillis();
System.out.print("结束时间:"+endTime);
System.out.print("---------------------------------");
System.out.print((benginTime-endTime)/1000);
}