excel数据

    a-title b-title c-title d-title
    c-sub-1 c-sub-2 d-sub-1 d-sub-2
    1 2 3 4 5 6
    6 4 5 2 2 2

    定义导入时的映射对象:

    1. @Data
    2. public class Content {
    3. @ExcelProperty(index = 0)
    4. private String field1;
    5. @ExcelProperty(index = 1)
    6. private String field2;
    7. @ExcelProperty(index = 2)
    8. private String field3;
    9. @ExcelProperty(index = 3)
    10. private String field4;
    11. @ExcelProperty(index = 4)
    12. private String field5;
    13. @ExcelProperty(index = 5)
    14. private String field6;
    15. }

    读取内容:

    1. public class MainTest{
    2. public static void main(String[] args){
    3. ExcelReader build = EasyExcel.read(new File("/home/demo.xlsx")).build();
    4. SyncReadListener syncReadListener = new SyncReadListener();
    5. ReadSheet readSheet1 =
    6. EasyExcel.readSheet(0).head(Content.class).registerReadListener(syncReadListener).build();
    7. build.read(Arrays.asList(readSheet1));
    8. syncReadListener.getList().forEach(x -> System.out.println(x.toString()));
    9. }
    10. }

    输出内容为:
    Content(field1=null, field2=null, field3=c-sub-1, field4=c-sub-2, field5=d-sub-1, field6=d-sub-2)
    Content(field1=1, field2=2, field3=3, field4=4, field5=5, field6=6)
    Content(field1=6, field2=4, field3=5, field4=2, field5=2, field6=2)

    此时数据已经读入,且映射完成,但是第一行数据是部分表头数据,是无效数据