From db6f19fdcae1d505f6d254e43335cef8d27a7400 Mon Sep 17 00:00:00 2001 From: jianjun Date: Mon, 1 Nov 2021 15:49:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/IcResiUserController.java | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java index e00e092d1b..f1100c3901 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java @@ -46,7 +46,6 @@ import com.epmet.excel.IcResiUserExcel; import com.epmet.feign.OperCustomizeOpenFeignClient; import com.epmet.service.IcResiUserService; import org.apache.commons.lang3.StringUtils; -import org.apache.poi.ss.usermodel.Name; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; @@ -152,14 +151,15 @@ public class IcResiUserController { for (Map.Entry> entry : sheetHeaderMap.entrySet()) { String sheetName = entry.getKey(); List headers = entry.getValue(); - ExportParams exportParams = new ExportParams(); - exportParams.setSheetName(sheetName); - exportParams.setAutoSize(true); - new ExcelExportService().createSheetForMap(workbook, exportParams, headers,new ArrayList<>()); + System.out.println("headers:"+sheetName+JSON.toJSONString(headers)); + ExportParams exportParams = new ExportParams(null,sheetName); + //exportParams.setAutoSize(true); + List> dataSet = new ArrayList<>(); + HashMap map = new HashMap<>(); + map.put("1","2"); + dataSet.add(map); + new ExcelExportService().createSheetForMap(workbook, exportParams, headers, dataSet); } - List allNames = workbook.getAllNames(); - System.out.println("======"+allNames); - FileOutputStream fos = new FileOutputStream("//Users/liujianjun/Downloads/基础信息表/Dow.tt.xls"); workbook.write(fos); @@ -176,38 +176,38 @@ public class IcResiUserController { Map> everySheetHeaderMap = new LinkedHashMap<>(); List firstSheetHeaderList = new ArrayList<>(); + //Map groupNameMap = groupList.stream().collect(Collectors.toMap(FormGroupDTO::getGroupId,FormGroupDTO::getLabel)); itemList.forEach(item->{ if (StringUtils.isBlank(item.getColumnName())){ return; } - ExcelExportEntity header = new ExcelExportEntity(item.getLabel(),item.getColumnName().concat(String.valueOf(item.getColumnNum())),30); - header.setNeedMerge(true); if (item.getChildGroup() == null){ - System.out.println(item.getLabel()); + ExcelExportEntity header = new ExcelExportEntity(item.getLabel(),item.getColumnName().concat(String.valueOf(item.getColumnNum())),30); + header.setNeedMerge(true); firstSheetHeaderList.add(header); return; } everySheetHeaderMap.putIfAbsent(resultForm.getData().getFormName(),firstSheetHeaderList); + //这些是动态的 formGroup if (item.getChildGroup() != null){ //baseTableName单独的一个sheet System.out.println("childGroup:"+item.getLabel()); if (BASE_TABLE_NAME.equals(item.getTableName())){ - header = new ExcelExportEntity(item.getChildGroup().getLabel(),item.getChildGroup().getTableName()); - header.setNeedMerge(true); + // header = new ExcelExportEntity(item.getChildGroup().getLabel(),item.getChildGroup().getTableName()); + //header.setNeedMerge(true); List otherSheetHeaderList = new ArrayList<>(); - List secondHeaderList = new ArrayList<>(); //这里是设置除基础信息之外的sheet的表头 item.getChildGroup().getItemList().forEach(item2->{ if (!BASE_TABLE_NAME.equals(item2.getTableName())){ - everySheetHeaderMap.putIfAbsent(item.getLabel(),otherSheetHeaderList); } ExcelExportEntity secondHeader = new ExcelExportEntity(item2.getLabel(),item2.getColumnName().concat(String.valueOf(item2.getColumnNum()))); - secondHeader.setNeedMerge(true); - secondHeaderList.add(secondHeader); - if (!item2.getItemType().equals("radio") && com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isNotEmpty(item2.getOptions())){ + + otherSheetHeaderList.add(secondHeader); + if (!"radio".equals(item2.getItemType()) && CollectionUtils.isNotEmpty(item2.getOptions())){ + secondHeader.setNeedMerge(true); List thirdHeaderList = new ArrayList<>(); item2.getOptions().forEach(child->{ ExcelExportEntity thirdHeader = new ExcelExportEntity(child.getLabel()); @@ -217,18 +217,16 @@ public class IcResiUserController { } }); - header.setList(secondHeaderList); - otherSheetHeaderList.add(header); + //header.setList(secondHeaderList); + //otherSheetHeaderList.add(header); } } }); - //List firstSheetHeaderList = new ArrayList<>(); groupList.forEach(item->{ /* if (!"兴趣爱好".equals(item.getLabel()) && !"宗教信仰".equals(item.getLabel())){ return; }*/ - if (!BASE_TABLE_NAME.equals(item.getTableName())){ - System.out.println(item.getLabel()+"--"+item.getTableName()); + if (!BASE_TABLE_NAME.equals(item.getTableName())){ return; } ExcelExportEntity header = new ExcelExportEntity(item.getLabel(),item.getTableName());