easyExcel动态生成表头

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

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

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

            head.add("日期");
            headList.add(head);
            for (Map.Entry> entry : dataMap.entrySet()){
                List 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();

 

 最后实现的效果如下图:

 

你可能感兴趣的:(easyExcel动态生成表头)