From 18135e77fc62fbd3cdd6d789a4edc49e417e78a9 Mon Sep 17 00:00:00 2001 From: jishenfei Date: Fri, 7 Apr 2023 16:44:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E9=83=A8=E5=AD=95=E5=A6=87=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=AF=BC=E5=87=BA=E6=95=B0=E6=8D=AE=E4=B8=AD=E9=9A=90?= =?UTF-8?q?=E8=97=8F=E5=AD=97=E6=AE=B5=E5=92=8C=E8=B0=83=E6=95=B4=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform-common/pom.xml | 7 ++- .../com/lyms/platform/common/utils/ExcelUtil.java | 58 ++++++++++++++++++++++ .../platform/operate/web/facade/PatientFacade.java | 20 ++++++-- 3 files changed, 80 insertions(+), 5 deletions(-) diff --git a/platform-common/pom.xml b/platform-common/pom.xml index f69b730..2f88a4b 100644 --- a/platform-common/pom.xml +++ b/platform-common/pom.xml @@ -39,7 +39,12 @@ commons-lang3 3.4 - + + org.apache.poi + poi-ooxml-schemas + 3.15 + + diff --git a/platform-common/src/main/java/com/lyms/platform/common/utils/ExcelUtil.java b/platform-common/src/main/java/com/lyms/platform/common/utils/ExcelUtil.java index 4ae4d39..f09cb1a 100644 --- a/platform-common/src/main/java/com/lyms/platform/common/utils/ExcelUtil.java +++ b/platform-common/src/main/java/com/lyms/platform/common/utils/ExcelUtil.java @@ -114,7 +114,62 @@ public class ExcelUtil { WritableWorkbook wwb; try { wwb = Workbook.createWorkbook(out); + + WritableSheet ws = wwb.createSheet("sheet", 0); // 创建一个工作表 + + /** + * 设置单元格样式 + */ + WritableFont wf = new WritableFont(WritableFont.ARIAL, 12, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK); + WritableCellFormat wcf = new WritableCellFormat(wf); + ws.setRowView(0, 300); // 设置指定行高 + // 设置列宽 + for (int j = 0, columLen = columName.size(); j < columLen; j++) { + ws.setColumnView(j, 15); + } + // 填充数据的内容 + Map map; + for (int i = 0, len = data.size(); i < len; i++) { + map = data.get(i); + Iterator ite = columName.keySet().iterator(); + int j = 0; + String keyORvalue = ""; + String keyName = ""; + while (ite.hasNext()) { + keyName = ite.next(); + if (i > 0) { // 类容数据 + keyORvalue = map.get(keyName) == null ? "" : map.get(keyName).toString(); + } else { // 第一行列名 + keyORvalue = map.get(keyName) == null ? "" : map.get(keyName).toString(); + keyName = columName.get(keyName); + ws.addCell(new Label(j, 0, keyName, wcf)); + } + ws.addCell(new Label(j, 1 + i, keyORvalue)); + j++; + } + } + + + wwb.write(); + wwb.close(); + } catch (IOException e) { + e.printStackTrace(); + } catch (RowsExceededException e) { + e.printStackTrace(); + } catch (WriteException e) { + e.printStackTrace(); + } + return out; + } + + //导出时隐藏列 + public static OutputStream toExcelhideLie(OutputStream out, List> data, Map columName) { + WritableWorkbook wwb; + try { + wwb = Workbook.createWorkbook(out); + WritableSheet ws = wwb.createSheet("sheet", 0); // 创建一个工作表 + /** * 设置单元格样式 */ @@ -141,12 +196,15 @@ public class ExcelUtil { keyORvalue = map.get(keyName) == null ? "" : map.get(keyName).toString(); keyName = columName.get(keyName); ws.addCell(new Label(j, 0, keyName, wcf)); + ws.setColumnView(6, 0); + ws.setColumnView(18, 0); } ws.addCell(new Label(j, 1 + i, keyORvalue)); j++; } } + wwb.write(); wwb.close(); } catch (IOException e) { diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/PatientFacade.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/PatientFacade.java index b9e7686..b2ec76a 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/PatientFacade.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/PatientFacade.java @@ -2202,6 +2202,7 @@ public class PatientFacade extends BaseServiceImpl { HttpServletResponse response) { response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment;fileName=" + "datas.xls"); + Boolean isHideArea = false; try { String hospital = autoMatchFacade.getHospitalId(userId); BaseListResponse listResponse = null; @@ -2256,6 +2257,7 @@ public class PatientFacade extends BaseServiceImpl { data.put("vcCardNo", rp.getVcCardNo()); } data.put("cardNo", rp.getCardNo()); + data.put("phone", patientsQueryRequest.getIsEncry() == 0 ? rp.getRealPhone() : com.lyms.platform.common.utils.StringUtils.encryPhone(rp.getRealPhone())); data.put("dueWeek", rp.getDueWeek()); data.put("bTime", rp.getbTime()); data.put("cTimes", rp.getcTimes()); @@ -2269,7 +2271,7 @@ public class PatientFacade extends BaseServiceImpl { data.put("currentCh", rp.getCurrentCh()); data.put("checkDoctor", rp.getCheckDoctor()); data.put("lName", rp.getlName()); - data.put("phone", patientsQueryRequest.getIsEncry() == 0 ? rp.getRealPhone() : com.lyms.platform.common.utils.StringUtils.encryPhone(rp.getRealPhone())); + //首次建档医院 data.put("firstBH", rp.getFirstBH()); data.put("serviceType", rp.getServiceType()); @@ -2333,6 +2335,7 @@ public class PatientFacade extends BaseServiceImpl { cnames.put("vcCardNo", "就诊卡号"); } cnames.put("cardNo", "身份证"); + cnames.put("phone", "联系方式"); cnames.put("dueWeek", "当前孕周"); cnames.put("bTime", "建档日期"); cnames.put("normal", "建档状态"); @@ -2346,11 +2349,12 @@ public class PatientFacade extends BaseServiceImpl { cnames.put("currentCh", "当前产检医院"); cnames.put("checkDoctor", "产检医生"); cnames.put("lName", "登记人"); - cnames.put("phone", "联系方式"); + cnames.put("firstBH", "首次建档医院"); cnames.put("serviceType", "服务类型"); cnames.put("serviceStatus", "服务状态"); cnames.put("remark", "备注"); + isHideArea =true; }else { //全部产妇 cnames.put("name", "姓名"); @@ -2372,8 +2376,16 @@ public class PatientFacade extends BaseServiceImpl { cnames.put("cardNo", "身份证号码"); cnames.put("remark", "备注"); } - OutputStream out = response.getOutputStream(); - ExcelUtil.toExcel(out, datas, cnames); + + if (isHideArea){ + OutputStream out = response.getOutputStream(); + ExcelUtil.toExcelhideLie(out, datas, cnames); + }else{ + OutputStream out = response.getOutputStream(); + ExcelUtil.toExcel(out, datas, cnames); + } + + } catch (Exception e) { ExceptionUtils.catchException(e, e.getMessage()); } -- 1.8.3.1