2.SAX导入(支持csv文件导入)
- URL htmlToExcelEampleURL = this.getClass().getResource("/templates/read_example.xlsx");
- Path path = Paths.get(htmlToExcelEampleURL.toURI());
-
- // 方式一:全部读取后处理,SAX模式,避免OOM,建议大量数据使用
- List<ArtCrowd> result = SaxExcelReader.of(ArtCrowd.class)
- .sheet(0) // 0代表第一个,如果为0,可省略该操作,也可sheet("名称")读取
- .rowFilter(row -> row.getRowNum() > 0) // 如无需过滤,可省略该操作,0代表第一行
- .beanFilter(ArtCrowd::isDance) // bean过滤
-
- // 方式二:读取一行处理一行,可自行决定终止条件,SAX模式,避免OOM,建议大量数据使用
- // readThen有两种重写接口,返回Boolean型接口允许在返回False情况下直接终止读取
- SaxExcelReader.of(ArtCrowd.class)
- .sheet(0) // 0代表第一个,如果为0,可省略该操作,也可sheet("名称")读取
- .rowFilter(row -> row.getRowNum() > 0) // 如无需过滤,可省略该操作,0代表第一行
- .beanFilter(ArtCrowd::isDance) // bean过滤
- .readThen(path.toFile() ,artCrowd -> {System.out.println(artCrowd.getName);});// 可接收inputStream
-
- // index代表列索引,从0开始
- @ExcelColumn(index = 0)
- private String name;
-
- @ExcelColumn(index = 1)
- private String age;
-
- @ExcelColumn(index = 2,dateFormatPattern="yyyy-MM-dd")
- private Date birthday;