easyexcel(二)读

 

读取excel需要先写一个监听器继承 AnalysisEventListener

    //使用无映射读取数据
    @Test
    public void noModel() throws FileNotFoundException {
        FileInputStream in=new FileInputStream("test2.xls");
        //AnalysisEventListener的匿名内部类
        AnalysisEventListener<List<String>> listener=new AnalysisEventListener<List<String>>() {
            @Override
            public void invoke(List<String> object, AnalysisContext context) {
                System.out.println(context.getCurrentRowNum()+" data:"+object);
            }

            @Override
            public void doAfterAllAnalysed(AnalysisContext context) {
                System.out.println("doAfterAllAnalysed...");
            }
        };

        ExcelReader reader= EasyExcelFactory.getReader(new BufferedInputStream(in),listener);
        reader.read();
    }

  //使用有映射模型读取数据...

 

posted @ 2020-08-24 15:39  hjy1995  阅读(237)  评论(0编辑  收藏  举报