MyExcel 3.7.0 released, shielding the details of multi-threaded processing

MyExcel is a Java toolkit that integrates multiple functions such as import, export, and encrypted Excel.

MyExcel uses declarative syntax to build and read Excel, shielding the specific operational details of POI (not aware of POI), and replacing it with the development of commonly used technologies, which makes building (from simple to highly complex Excel) and reading Excel extremely convenient , And the construction and reading performance is extremely excellent, and the memory consumption is extremely low (for details, please refer to the performance comparison of MyExcel & Ali EasyExcel ).

Such as import:

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());

This is a routine update. The specific updates are as follows:

  • DefaultStreamExcelBuilder adds asyncAppend method to shield multi-thread usage details;
  • Optimize FreemarkerTemplateHandler, add support for Java8 time class;
  • Optimize reading information of abnormal fields;

Shielding the use of multithreading details (asyncAppend internal implementation is still multithreading), is to lower the threshold of asynchronous export, so that Java beginners or users who are not familiar with multithreading can quickly start MyExcel streaming export, and try to reduce each line of user code! ! !

Original streaming export method:

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);
}

Optimized streaming export method:

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);
}

For details, please move to the document: https://github.com/liaochong/myexcel/wiki/Excel%E6%B5%81%E5%BC%8F%E5%AF%BC%E5%87%BA

Guess you like

Origin www.oschina.net/news/114840/myexcel-3-7-0-released