Excel 导出效率


title: Excel 导出效率 tags:

  • easypoi
  • 导出
  • 效率
  • excel categories: 工作日志 date: 2017-08-18 18:18:51

参考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.0modelVersion>
     
        <groupId>me.qixiaobogroupId>
        <artifactId>easypoi-testartifactId>
        <version>1.0-SNAPSHOTversion>
        <properties>
            <easypoi.version>2.4.0easypoi.version>
            <f6car.version>1.1.16f6car.version>
        properties>
        <dependencies>
     
            <dependency>
                <groupId>org.jeecggroupId>
                <artifactId>easypoi-baseartifactId>
                <version>${easypoi.version}version>
            dependency>
            <dependency>
                <groupId>org.jeecggroupId>
                <artifactId>easypoi-webartifactId>
                <version>${easypoi.version}version>
            dependency>
            <dependency>
                <groupId>org.jeecggroupId>
                <artifactId>easypoi-annotationartifactId>
                <version>${easypoi.version}version>
            dependency>
            <dependency>
                <artifactId>biz-voartifactId>
                <groupId>com.f6car.erpgroupId>
                <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 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 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

git.oschina.net/qixiaobo/ea…

你可能感兴趣的:(Excel 导出效率)