MyExcel,是一个集导入、导出、加密 Excel 等多项功能的 Java 工具包。
MyExcel 采用声明式语法来构建、读取 Excel,屏蔽 POI 的具体操作细节(对 POI 无感知),以开发常用的技术替代,使得构建(从简单到高度复杂 Excel)以及读取 Excel 变得极为便利,且构建、读取性能极为优异,占用内存极低。
如导入:
List<ArtCrowd> result = SaxExcelReader.of(ArtCrowd.class) .sheet(0) // 0代表第一个sheet,如果为0,可省略该操作,也可sheet("名称")读取 .rowFilter(row -> row.getRowNum() > 0) // 如无需过滤,可省略该操作,0代表第一行 .detectedMerge() // 识别合并单元格并填充数据,默认不识别 .read(path);
本次更新如下:
- 修复DefaultExcelBuilder调用hideColumns无效问题;
- SaxExcelReader支持一对多导入;
- 调整DefaultStreamExcelBuilder等待队列长度,提升导出性能;
- 升级imageio-jpeg版本为3.8.2;
一对多导入示例
示例1
URL htmlToExcelEampleURL = this.getClass().getResource("/muilt_read.xlsx"); Path path = Paths.get(htmlToExcelEampleURL.toURI()); List<Grade> multiParents = SaxExcelReader.of(Grade.class) .rowFilter(row -> row.getRowNum() > 0) .detectedMerge() // 必须要调用识别合并单元格方法,否则无效 .read(Files.newInputStream(path)); public class Grade { @ExcelColumn(index=0) private String gradeName; @MultiColumn(classType=String.class) @ExcelColumn(index=1) private List<String> studentNames; @MultiColumn(classType=Integer.class) @ExcelColumn(index=2) private List<Integer> studentAges; }
示例2
URL htmlToExcelEampleURL = this.getClass().getResource("/muilt_read.xlsx"); Path path = Paths.get(htmlToExcelEampleURL.toURI()); List<Grade> multiParents = SaxExcelReader.of(Grade.class) .rowFilter(row -> row.getRowNum() > 0) .detectedMerge() // 必须要调用识别合并单元格方法,否则无效 .read(Files.newInputStream(path)); public class Grade { @ExcelColumn(index=0) private String gradeName; @MultiColumn(classType=Student.class) private List<Student> students; } public class Student { @ExcelColumn(index=1) private String name; @ExcelColumn(index=2) private Integer age; }
示例3
URL htmlToExcelEampleURL = this.getClass().getResource("/muilt_read.xlsx"); Path path = Paths.get(htmlToExcelEampleURL.toURI()); List<School> multiParents = SaxExcelReader.of(School.class) .rowFilter(row -> row.getRowNum() > 0) .detectedMerge() // 必须要调用识别合并单元格方法,否则无效 .read(Files.newInputStream(path)); public class School { @ExcelColumn(index=0) private String name; @MultiColumn(classType=Grade.class) private List<Grade> grades; } public class Grade { @ExcelColumn(index=1) private String gradeName; @MultiColumn(classType=Student.class) private List<Student> students; } public class Student { @ExcelColumn(index=2) private String name; @ExcelColumn(index=3) private Integer age; }
具体,请移步文档:https://github.com/liaochong/myexcel/wiki
还没有评论,来说两句吧...