1.excel中1个sheet行上限是1048576,当导出数据行数超过时,会抛出io异常,此时产生的xml临时文件没有删除 2.当导出的字段数量比较多时,产生的临时文件占用比较大,下面的Demo中,100万条数据,占用大概1.6g,由于不会删除,因此会逐渐占满系统磁盘空间
断点打到最后,发现临时文件没有删除,当程序结束,也就是jvm关闭或者tomcat重启,临时文件才会删除。
测试代码import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.util.FileUtils;
import com.alibaba.excel.write.metadata.WriteSheet;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
class DemoData{
@ExcelProperty(value = "id")
private String id;
@ExcelProperty(value = "商品")
private String commodityName;
@ExcelProperty(value = "商品2")
private String commodityName2;
@ExcelProperty(value = "商品3")
private String commodityName3;
@ExcelProperty(value = "商品4")
private String commodityName4;
@ExcelProperty(value = "商品5")
private String commodityName5;
@ExcelProperty(value = "商品6")
private String commodityName6;
@ExcelProperty(value = "商品7")
private String commodityName7;
@ExcelProperty(value = "商品8")
private String commodityName8;
}
public class Testa {
public static void main(String[] args) {
System.out.println(FileUtils.getPoiFilesPath());
String filePath = "/tmp/test.xlsx";
ExcelWriter writer = EasyExcel.write(filePath).excelType(ExcelTypeEnum.XLSX).build();
WriteSheet sheet = EasyExcel.writerSheet().head(DemoData.class).build();
try{
for (int i = 0; i < 10000; i++) {
List<DemoData> rowData = new ArrayList<>();
for (int j = 0; j < 110; j++) {
DemoData excelVo = new DemoData();
excelVo.setId("" + (i * 110 + j));
rowData.add(excelVo);
}
writer.write(rowData, sheet);
}
writer.finish();
}catch (Exception e){
e.printStackTrace();
}
System.out.println("导出执行完毕");
}
}