easyExcel动态生成表头

 之前的都是固定格式处理excel,这次是动态的导出excel,下边是处理表头的,主要就是把表头放到headList

List<List<Object>> list = new ArrayList<>();
            //向Excel写入数据
            ExcelWriter writer = EasyExcelFactory.getWriter(out);
            // 表单
            Sheet sheet = new Sheet(1,0);
            sheet.setSheetName("产量对比");
            // 创建一个表格
            Table table = new Table(1);

            List<List<String>> headList = new ArrayList<List<String>>();
            List<String> head = new ArrayList<>();
            List<String> production = new ArrayList<>();

            head.add("日期");
            headList.add(head);
            for (Map.Entry<String, HashMap<String, Double>> entry : dataMap.entrySet()){
                List<String> head1 = new ArrayList<>();
                String key = entry.getKey();//uwi
                head1.add("井"+key);
                headList.add(head1);
            }
            production.add("平均产量");
            headList.add(production);

 最后把headList放到table中

table.setHead(headList);
            writer.write1(list,sheet,table);
            writer.finish();

 最后实现的效果如下图:

 

发布了46 篇原创文章 · 获赞 4 · 访问量 5030

猜你喜欢

转载自blog.csdn.net/qq_35862393/article/details/102949615