فهرست منبع

宿管值班安排表导出

dzx 1 سال پیش
والد
کامیت
119ca9fc73

+ 1 - 1
src/main/java/com/xjrsoft/module/room/util/CustomCellRangeAddress.java → src/main/java/com/xjrsoft/common/utils/excel/CustomCellRangeAddress.java

@@ -1,4 +1,4 @@
-package com.xjrsoft.module.room.util;
+package com.xjrsoft.common.utils.excel;
 
 import org.apache.poi.ss.util.CellRangeAddress;
 

+ 52 - 0
src/main/java/com/xjrsoft/common/utils/excel/HandleUtil.java

@@ -0,0 +1,52 @@
+package com.xjrsoft.common.utils.excel;
+
+import org.apache.poi.ss.usermodel.BorderStyle;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.usermodel.VerticalAlignment;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.usermodel.XSSFCell;
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
+import org.apache.poi.xssf.usermodel.XSSFFont;
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+/**
+ * @author dzx
+ * @date 2024/1/8
+ */
+public class HandleUtil {
+
+    public static void setRegionStyle(XSSFSheet sheet, CellRangeAddress region, XSSFCellStyle xssfCellStyle) {
+        for (int i = region.getFirstRow(); i <= region.getLastRow(); i++) {
+            XSSFRow row = sheet.getRow(i);
+            if (null == row) row = sheet.createRow(i);
+            for (int j = region.getFirstColumn(); j <= region.getLastColumn(); j++) {
+                XSSFCell cell = row.getCell(j);
+                if (null == cell) cell = row.createCell(j);
+                cell.setCellStyle(xssfCellStyle);
+            }
+        }
+    }
+
+    public static XSSFCellStyle setDefaultStyle(XSSFWorkbook workbook, Boolean isBold) {
+        XSSFCellStyle cellStyle = workbook.createCellStyle();
+        // 边框
+        cellStyle.setBorderBottom(BorderStyle.THIN);
+        cellStyle.setBorderLeft(BorderStyle.THIN);
+        cellStyle.setBorderRight(BorderStyle.THIN);
+        cellStyle.setBorderTop(BorderStyle.THIN);
+        // 居中
+        cellStyle.setAlignment(HorizontalAlignment.CENTER);
+        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+        // 字体
+        XSSFFont font = workbook.createFont();
+        font.setFontName("Calibri");
+        if(isBold){
+            font.setBold(isBold);
+        }
+        font.setFontHeightInPoints((short) 10);
+        cellStyle.setFont(font);
+        return cellStyle;
+    }
+}

+ 5 - 41
src/main/java/com/xjrsoft/module/room/controller/RoomValueWeekController.java

@@ -10,11 +10,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.xjrsoft.common.model.result.RT;
 import com.xjrsoft.common.page.ConventPage;
 import com.xjrsoft.common.page.PageOutput;
+import com.xjrsoft.common.utils.excel.CustomCellRangeAddress;
+import com.xjrsoft.common.utils.excel.HandleUtil;
 import com.xjrsoft.module.room.dto.AddRoomValueWeekDto;
 import com.xjrsoft.module.room.dto.RoomValueWeekPageDto;
 import com.xjrsoft.module.room.dto.UpdateRoomValueWeekDto;
 import com.xjrsoft.module.room.service.IRoomValueWeekService;
-import com.xjrsoft.module.room.util.CustomCellRangeAddress;
 import com.xjrsoft.module.room.vo.RoomValueWeekExcelVo;
 import com.xjrsoft.module.room.vo.RoomValueWeekItemExcelVo;
 import com.xjrsoft.module.room.vo.RoomValueWeekItemVo;
@@ -22,14 +23,7 @@ import com.xjrsoft.module.room.vo.RoomValueWeekPageVo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
-import org.apache.poi.ss.usermodel.BorderStyle;
-import org.apache.poi.ss.usermodel.HorizontalAlignment;
-import org.apache.poi.ss.usermodel.VerticalAlignment;
 import org.apache.poi.ss.util.CellRangeAddress;
-import org.apache.poi.xssf.usermodel.XSSFCell;
-import org.apache.poi.xssf.usermodel.XSSFCellStyle;
-import org.apache.poi.xssf.usermodel.XSSFFont;
-import org.apache.poi.xssf.usermodel.XSSFRow;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.http.ResponseEntity;
@@ -169,12 +163,13 @@ public class RoomValueWeekController {
         //使用poi合并单元格,使用registerWriteHandler合并单元格会与fill方法中创建单元格后校验合并单元格冲突而引发报错
         XSSFWorkbook workbook = new XSSFWorkbook(in);
         XSSFSheet sheetAt = workbook.getSheet(sheetName);
-
+        //合并单元格
         for (CellRangeAddress cellRangeAddress : cellRangeAddressList) {
             sheetAt.addMergedRegion(cellRangeAddress);
         }
+        //设置样式
         for (CustomCellRangeAddress cellRangeAddress : styleList) {
-            setRegionStyle(sheetAt, cellRangeAddress, setDefaultStyle(workbook, cellRangeAddress.getIsBlod()));
+            HandleUtil.setRegionStyle(sheetAt, cellRangeAddress, HandleUtil.setDefaultStyle(workbook, cellRangeAddress.getIsBlod()));
         }
 
         ByteArrayOutputStream os = new ByteArrayOutputStream();
@@ -185,36 +180,5 @@ public class RoomValueWeekController {
         return RT.fileStream(os.toByteArray(), fileName);
     }
 
-    public void setRegionStyle(XSSFSheet sheet, CellRangeAddress region, XSSFCellStyle xssfCellStyle) {
-        for (int i = region.getFirstRow(); i <= region.getLastRow(); i++) {
-            XSSFRow row = sheet.getRow(i);
-            if (null == row) row = sheet.createRow(i);
-            for (int j = region.getFirstColumn(); j <= region.getLastColumn(); j++) {
-                XSSFCell cell = row.getCell(j);
-                if (null == cell) cell = row.createCell(j);
-                cell.setCellStyle(xssfCellStyle);
-            }
-        }
-    }
 
-    public XSSFCellStyle setDefaultStyle(XSSFWorkbook workbook, Boolean isBold) {
-        XSSFCellStyle cellStyle = workbook.createCellStyle();
-        // 边框
-        cellStyle.setBorderBottom(BorderStyle.THIN);
-        cellStyle.setBorderLeft(BorderStyle.THIN);
-        cellStyle.setBorderRight(BorderStyle.THIN);
-        cellStyle.setBorderTop(BorderStyle.THIN);
-        // 居中
-        cellStyle.setAlignment(HorizontalAlignment.CENTER);
-        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
-        // 字体
-        XSSFFont font = workbook.createFont();
-        font.setFontName("Calibri");
-        if(isBold){
-            font.setBold(isBold);
-        }
-        font.setFontHeightInPoints((short) 10);
-        cellStyle.setFont(font);
-        return cellStyle;
-    }
 }