知识:easyPOI动态表头

数据不是一成不变的,表格数据的表头也是可删可减,这个时候怎么处理动态表头呢(此处动态表头的数据来自与后端查询所得数据后端

说明:没有使用过这个注解,网坛上有人说,这个只是隐藏好像仍是会导出,这个光荣而又艰巨的任务就交给各位了code

/**
 * 动态列导出
 * @param response
 * @param param 设置表的文件名和sheet名
 * @param headList 表头
 * @param list 数据源
 * @throws IOException
 */
public static void exportActiveSheet(HttpServletResponse response, ExportParams param, List<ExcelExportEntity> headList, List<Map<String, Object>> list) throws IOException {
    Workbook workbook = null;
    workbook = ExcelExportUtil.exportExcel(param, headList,list);
    if (workbook != null) {
        downLoadExcel(param.getIndexName(), response, workbook);
    }
}

在业务层你须要get

List<ExcelExportEntity> colList = new ArrayList<>();定义全局的colList 就是表头设置
ExcelExportEntity colEntity = new ExcelExportEntity("表头名称", "键");
colEntity.setNeedMerge(true);
colEntity.setWidth(30);
colEntity.setHeight(20);
.....不少格式或姿式你均可以在这里设置
colList.add(colEntity);


动态列表头it

ExcelExportEntity desginsGroup = new ExcelExportEntity("表头名称", "键");//设置整个动态列所属列能够不要名称
List<ExcelExportEntity> paramCols = new ArrayList<>();动态列表头的集合
list.forEach(item->{// list 动态列表头显示数据,使用forEach请注意本身jdk的版本
    // 为了方便后面匹配数据,这里指定key和名称最好一至,方便匹配数值
    // 动态列
    paramCols.add(new ExcelExportEntity(item.getOfficeName(), item.getOfficeName(),30));
});
desginsGroup.setList(paramCols);
colList.add(desginsGroup);


最后就是数据源了io

List<Map<String, Object>> list2 = new ArrayList<Map<String, Object>>();
list.forEach(item->{
    Map<String, Object> valMap = new HashMap<String, Object>();
    valMap.put("projectName", item.getProjectName());
    List<Map<String, Object>> deliDetailList = new ArrayList<Map<String, Object>>();
    Map<String, Object> deliValMap = new HashMap<String, Object>();
    item.getList().forEach(item2->{
        deliValMap.put(item2.getOfficeName(), item2.getDesginArea());
    });
    deliDetailList.add(deliValMap);
    valMap.put("desgins", deliDetailList);
    list2.add(valMap);
});


怎么调用就不用我写了吧jdk