|
|
@@ -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;
|
|
|
- }
|
|
|
}
|