MyExcel 3.6.0 release, the list of supported mixed templates & Export

MyExcel, is a set of import, export, encryption, Excel and many other features of Java toolkit.

MyExcel constructed using declarative syntax, read Excel, specific operational details POI shield (no perception of the POI), to develop alternative conventional techniques, such construct (from the simple to the highly complex Excel) Excel and reading becomes very convenient and constructing, read performance is extremely excellent in low memory footprint (in particular, please refer to the venue MyExcel & Ali EasyExcel performance comparison ).

The Import:

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

The updates are as follows:

  1. Reconstruction Template builder ExcelBuilder, using TemplateHandler template parsing process;
  2. DefaultStreamExcelBuilder additional support templates ;
  3. New MyExcelConfiguration, support for MyExcel be set globally, such as a custom temporary file directory;
  4. Resource optimization ExcelBuilder processing, improve the efficiency of template building;
  5. Rename @ExcelModel like configuration corresponding to the class name annotation, easy to understand;
  6. Optimization unit test file storage directory, to avoid the clone can not perform unit testing questions directly;

In some cases, you may need to personalize the header, or summaries, and so, these requirements may involve complex layout merge rows, columns, and other styles, but the exported data may be relatively large, DefaultStreamExcelBuilderin itself is not sufficient capability Bean support complex layouts, massive compatible data export and complex layout, version 3.6.0 and later, DefaultStreamExcelBuildersupport for additional templates, define complex layout template, the template is added as follows

Code Example:

try (DefaultStreamExcelBuilder<ArtCrowd> streamExcelBuilder = DefaultStreamExcelBuilder
                .of(ArtCrowd.class)
                .templateHandler(FreemarkerTemplateHandler.class)// 追加模板数据,可选,适合极度个性化数据导出
                .start()) {
    // 模板数据追加
    Map<String,Object> dataMap = this.getDataMap();
    streamExcelBuilder.append("/templates/test.ftl", dataMap);

    // 普通数据追加
    List<ArtCrowd> dataList = this.getDataList();
    streamExcelBuilder.append(dataList);

    // 最终构建
    Workbook workbook = defaultExcelBuilder.build();
    AttachmentExportUtil.export(workbook, "艺术生信息", response);
}

First, you need to specify a template processor: templateHandler (FreemarkerTemplateHandler.class), in addition to FreemarkerTemplateHandler, there BeetlTemplateHandler, EnjoyTemplateHandler, ThymeleafTemplateHandler other five common template processor;

Next, using the template data append additional method, which accepts absolute path and relative path template, an absolute path as follows:

append("C:/User/project/templates","test.ftl",dataMap);

The final results are as follows:

Specifically, the venue and documentation, see the streaming part Exporting: document

Guess you like

Origin www.oschina.net/news/114462/myexcel-3-6-0-released