MyExcel 3.7.0 发布,屏蔽多线程处理细节

栏目: 软件资讯 · 发布时间: 6年前

内容简介:MyExcel,是一个集导入、导出、加密Excel等多项功能的Java工具包。 MyExcel采用声明式语法来构建、读取Excel,屏蔽POI的具体操作细节(对POI无感知),以开发常用的技术替代,使得构建(从简单到高度复杂Excel)以...

MyExcel,是一个集导入、导出、加密Excel等多项功能的 Java 工具包。

MyExcel采用声明式语法来构建、读取Excel,屏蔽POI的具体操作细节(对POI无感知),以开发常用的技术替代,使得构建(从简单到高度复杂Excel)以及读取Excel变得极为便利,且构建、读取性能极为优异,占用内存极低(具体,请移步参考MyExcel&阿里EasyExcel性能对比)。

如导入:

List<ArtCrowd> result = SaxExcelReader.of(ArtCrowd.class)
        .sheet(0) // 0代表第一个sheet,如果为0,可省略该操作,也可sheet("名称")读取
        .rowFilter(row -> row.getRowNum() > 0) // 如无需过滤,可省略该操作,0代表第一行
        .beanFilter(ArtCrowd::isDance) // bean过滤
        .read(path.toFile());

本次为例行更新,具体更新如下:

  • DefaultStreamExcelBuilder新增asyncAppend方法,屏蔽多线程使用细节;
  • 优化FreemarkerTemplateHandler,增加对Java8时间类支持;
  • 优化读取异常字段的信息;

屏蔽多线程使用细节(asyncAppend内部实现依然是多线程),在于降低异步导出门槛,方便Java初学者或多线程不熟悉的用户能够快速入手MyExcel流式导出,尽力减少用户每一行代码!!!

原流式导出方式:

try (DefaultStreamExcelBuilder<ArtCrowd> streamExcelBuilder = DefaultStreamExcelBuilder
                .of(ArtCrowd.class)
                .threadPool(Executors.newFixedThreadPool(10))
                .start()) {
    // 多线程异步获取数据并追加至excel,join等待线程执行完成
    List<CompletableFuture> futures = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        CompletableFuture future = CompletableFuture.runAsync(() -> {
            List<ArtCrowd> dataList = this.getDataList();
            // 数据追加
            streamExcelBuilder.append(dataList);
        });
        futures.add(future);
    }
    futures.forEach(CompletableFuture::join);
    // 最终构建
    Workbook workbook = defaultExcelBuilder.build();
    AttachmentExportUtil.export(workbook, "艺术生信息", response);
}

优化后流式导出方式:

try (DefaultStreamExcelBuilder<ArtCrowd> streamExcelBuilder = DefaultStreamExcelBuilder
                .of(ArtCrowd.class)
                .threadPool(Executors.newFixedThreadPool(10))
                .start()) {
    for (int i = 0; i < 100; i++) {
        // 数据追加
        streamExcelBuilder.asyncAppend(this::getDataList);
    }
    // 最终构建
    Workbook workbook = defaultExcelBuilder.build();
    AttachmentExportUtil.export(workbook, "艺术生信息", response);
}

具体请移步文档:https://github.com/liaochong/myexcel/wiki/Excel%E6%B5%81%E5%BC%8F%E5%AF%BC%E5%87%BA

MyExcel 3.7.0 发布,屏蔽多线程处理细节


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Hackers

Hackers

Steven Levy / O'Reilly Media / 2010-5-30 / USD 21.99

This 25th anniversary edition of Steven Levy's classic book traces the exploits of the computer revolution's original hackers -- those brilliant and eccentric nerds from the late 1950s through the ear......一起来看看 《Hackers》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具