2.SAX导入(支持csv文件导入)

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