springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/HomeQuarantineUtil.java
@@ -48,7 +48,7 @@ continue; } if(count%16==2){ conditions.append(DateUtils.format(userAnswers.getTime(),new SimpleDateFormat("yyyy-MM-dd"))+" "+"当日隔离情况:"+userAnswers.getAnswerContent()+"℃"+"\n"); conditions.append(DateUtils.format(userAnswers.getTime(),new SimpleDateFormat("yyyy-MM-dd"))+" "+"当日隔离情况:"+userAnswers.getAnswerContent()+"\n"); conditions.append("————————"+"\n"); count++; continue; @@ -203,8 +203,18 @@ String answer = sb.toString(); userData.add(answer.substring(0, answer.length() - 1)); } for(List<Object> result:resultList){ if(result.get(4).equals(userData.get(4))){ String condition=result.get(result.size()-1)+userData.get(userData.size()-1).toString(); result.set(result.size()-1,condition); userData.set(userData.size()-1,null); break; } } if(userData.get(userData.size()-1)!=null){ resultList.add(userData); } } return resultList; } } springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/ComActReserveApi.java
@@ -25,6 +25,7 @@ import com.panzhihua.common.service.user.UserService; import com.panzhihua.common.utlis.*; import com.panzhihua.community_backstage.config.SFTPConfig; import com.panzhihua.community_backstage.excel.CustemSecondhandler; import com.panzhihua.community_backstage.excel.Custemhandler; import com.panzhihua.community_backstage.excel.CustomSheetWriteHandler; import io.swagger.annotations.Api; @@ -527,6 +528,45 @@ headList.add(head2); //数据转换 datalist = HomeQuarantineUtil.ReserveData(questnaireAnswersDTOS.getAnswers()); WriteCellStyle headWriteCellStyle = new WriteCellStyle(); //设置头居中 headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); //设置头字体 WriteFont headWriteFont = new WriteFont(); headWriteFont.setFontHeightInPoints((short)6); headWriteFont.setBold(true); headWriteCellStyle.setWriteFont(headWriteFont); WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); //设置表格内容字体 WriteFont writeFont = new WriteFont(); writeFont.setFontHeightInPoints((short)6); //设置 水平居中 contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.LEFT); //设置 垂直居中 contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); contentWriteCellStyle.setWriteFont(writeFont); contentWriteCellStyle.setWrapped(true); HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle); excelWriter = EasyExcel.write(fileName) .registerWriteHandler(horizontalCellStyleStrategy).registerWriteHandler(new CustemSecondhandler()) .build(); WriteSheet writeSheet = EasyExcel.writerSheet("登记明细导出数据").head(headList).build(); excelWriter.write(datalist, writeSheet); excelWriter.finish(); File file = new File(fileName); inputStream = new FileInputStream(file); sftp.uploadMore(ftpUrl, name, inputStream); sftp.logout(); inputStream.close(); String absolutePath = file.getAbsolutePath(); boolean delete = file.delete(); log.info("删除excel【{}】结果【{}】", absolutePath, delete); } else { String firstRowContent = "登记明细"; @@ -554,9 +594,6 @@ }); //数据转换 datalist = AssemblyUtils.ReserveData(questnaireAnswersDTOS.getAnswers()); } WriteCellStyle headWriteCellStyle = new WriteCellStyle(); //设置头居中 headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); @@ -584,7 +621,7 @@ excelWriter = EasyExcel.write(fileName) .registerWriteHandler(horizontalCellStyleStrategy).registerWriteHandler(new Custemhandler()) .registerWriteHandler(new CustomSheetWriteHandler()).build(); .build(); WriteSheet writeSheet = EasyExcel.writerSheet("登记明细导出数据").head(headList).build(); excelWriter.write(datalist, writeSheet); excelWriter.finish(); @@ -596,6 +633,10 @@ String absolutePath = file.getAbsolutePath(); boolean delete = file.delete(); log.info("删除excel【{}】结果【{}】", absolutePath, delete); } } finally { // 千万别忘记finish 会帮忙关闭流 if (inputStream != null) { springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/excel/CustemSecondhandler.java
New file @@ -0,0 +1,73 @@ package com.panzhihua.community_backstage.excel; import com.alibaba.excel.enums.CellDataTypeEnum; import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.Head; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; import com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy; import org.apache.poi.ss.usermodel.Cell; import org.springframework.util.CollectionUtils; import java.util.HashMap; import java.util.List; import java.util.Map; public class CustemSecondhandler extends AbstractColumnWidthStyleStrategy { private Map<Integer, Map<Integer, Integer>> CACHE = new HashMap(8); public CustemSecondhandler() { } @Override protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List<CellData> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) { boolean needSetWidth = isHead || !CollectionUtils.isEmpty(cellDataList); if (needSetWidth) { Map<Integer, Integer> maxColumnWidthMap = (Map)CACHE.get(writeSheetHolder.getSheetNo()); if (maxColumnWidthMap == null) { maxColumnWidthMap = new HashMap(16); CACHE.put(writeSheetHolder.getSheetNo(), maxColumnWidthMap); } Integer columnWidth = this.dataLength(cellDataList, cell, isHead); if (columnWidth >= 0) { if (columnWidth > 25) { columnWidth = 25; } Integer maxColumnWidth = (Integer)((Map)maxColumnWidthMap).get(cell.getColumnIndex()); if (maxColumnWidth == null || columnWidth > maxColumnWidth) { ((Map)maxColumnWidthMap).put(cell.getColumnIndex(), columnWidth); writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), columnWidth * 75); } if(cell.getStringCellValue().equals("隔离体温情况")){ writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(),70*75); } } } } private Integer dataLength(List<CellData> cellDataList, Cell cell, Boolean isHead) { if (isHead) { return cell.getStringCellValue().getBytes().length; } else { CellData cellData = cellDataList.get(0); CellDataTypeEnum type = cellData.getType(); if (type == null) { return -1; } else { switch(type) { case STRING: return cellData.getStringValue().getBytes().length; case BOOLEAN: return cellData.getBooleanValue().toString().getBytes().length; case NUMBER: return cellData.getNumberValue().toString().getBytes().length; default: return -1; } } } } }