excel文件数据行携带表头信息为map

    private List<Map<String, String>> readExcelForMap(InputStream input){
        List<Map<String, String>> list = new ArrayList<>();
        EasyExcel.read(input,new AnalysisEventListener<Map<String, String>>() {
            private Map<Integer, String> map;
            @Override
            public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
                this.map=headMap;
            }
            @Override
            public void invoke(Map<String, String> valueData, AnalysisContext context) {
                HashMap<String, String> pMap = new HashMap<>();
                for(int i=0;i<valueData.size();i++){
                    String key=map.get(i);
                    String value=valueData.get(i);
                    pMap.put(key,value);
                }
                list.add(pMap);
            }

            @Override
            public void doAfterAllAnalysed(AnalysisContext context) { }
        }).sheet().doRead();
        return list;
    }

  

posted @ 2024-04-03 09:57  梦-咖啡  阅读(15)  评论(0编辑  收藏  举报