Excel 导出效率

参考Excel导出改善 小伙伴问起导出效率如何

简单写了个样例

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
 
    <groupId>me.qixiaobo</groupId>
    <artifactId>easypoi-test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <easypoi.version>2.4.0</easypoi.version>
        <f6car.version>1.1.16</f6car.version>
    </properties>
    <dependencies>
 
        <dependency>
            <groupId>org.jeecg</groupId>
            <artifactId>easypoi-base</artifactId>
            <version>${easypoi.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jeecg</groupId>
            <artifactId>easypoi-web</artifactId>
            <version>${easypoi.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jeecg</groupId>
            <artifactId>easypoi-annotation</artifactId>
            <version>${easypoi.version}</version>
        </dependency>
        <dependency>
            <artifactId>biz-vo</artifactId>
            <groupId>com.f6car.erp</groupId>
            <version>${f6car.version}</version>
        </dependency>
    </dependencies>
 
</project>
import com.air.tqb.vo.MaintainRemindVO;
import com.Google.common.base.Stopwatch;
import com.google.common.collect.Lists;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
 
import Java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
 
public class Test {
    static final List<ExcelExportEntity> EXPORT_CUSTOMER_ENTITY_LIST = Lists.newArrayList();
    protected static final String HSSF = ".xls";
    protected static final String XSSF = ".xlsx";
 
 
    public static void main(String[] args) throws IOException {
        String codedFileName = "excel文件";
        ExportParams ep = new ExportParams(null, "客户车辆", ExcelType.XSSF);
        int length = 300000;
        List<MaintainRemindVO> list = Lists.newArrayListWithExpectedSize(length);
        for (int i = 0; i < length; i++) {
            MaintainRemindVO remindVO = new MaintainRemindVO();
            remindVO.setCarNo("A12" + i);
            remindVO.setNaCustomer("临时" + i);
            remindVO.setVin("12344" + i);
            remindVO.setCellPhone("12333" + i);
            list.add(remindVO);
        }
        Stopwatch stopwatch = Stopwatch.createStarted();
        Workbook workbook = ExcelExportUtil.exportExcel(ep, MaintainRemindVO.class, list);
        if (workbook instanceof HSSFWorkbook) {
            codedFileName += HSSF;
        } else {
            codedFileName += XSSF;
        }
        FileOutputStream fos = new FileOutputStream("/Users/qixiaobo/work/easypoitest/" + codedFileName);
        workbook.write(fos);
        fos.close();
        system.out.println("length:" + length + " cost:" + stopwatch.elapsed(TimeUnit.SECONDS)+"s");
    }
}

执行30w次输出如下

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
length:300000 cost:26s
Disconnected from the target VM, address: '127.0.0.1:50872', transport: 'socket'
Process finished with exit code 0

输出文件12M

导出30w条数据消耗26秒。基本满足日常需要

日常参数如下

-Xms512M -Xmx512M -XX:PermSize=64M

 http://git.oschina.net/qixiaobo/easypoitest

赞 (0) 评论 分享 ()