|
@@ -2,6 +2,7 @@ package cn.tr.module.excel.core.handler.write;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.*;
|
|
import cn.hutool.core.util.*;
|
|
|
|
|
+import cn.tr.module.export.annotation.ExcelCellMerge;
|
|
|
import cn.tr.module.export.annotation.ExcelSelect;
|
|
import cn.tr.module.export.annotation.ExcelSelect;
|
|
|
import cn.tr.module.export.annotation.ExcelPropertySupport;
|
|
import cn.tr.module.export.annotation.ExcelPropertySupport;
|
|
|
import cn.tr.module.export.handler.AbstractCascadeSelectConverter;
|
|
import cn.tr.module.export.handler.AbstractCascadeSelectConverter;
|
|
@@ -15,6 +16,7 @@ import lombok.Data;
|
|
|
import lombok.Getter;
|
|
import lombok.Getter;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
import org.apache.poi.ss.util.CellRangeAddressList;
|
|
import org.apache.poi.ss.util.CellRangeAddressList;
|
|
|
import org.apache.poi.xssf.usermodel.*;
|
|
import org.apache.poi.xssf.usermodel.*;
|
|
|
|
|
|
|
@@ -57,7 +59,41 @@ public class CustomCellWriteHandler implements CellWriteHandler {
|
|
|
//进行日期格式校验
|
|
//进行日期格式校验
|
|
|
createDateColumn(field,cell);
|
|
createDateColumn(field,cell);
|
|
|
columnIndexMap.put(field.getName(),cell.getColumnIndex());
|
|
columnIndexMap.put(field.getName(),cell.getColumnIndex());
|
|
|
|
|
+ }else {
|
|
|
|
|
+
|
|
|
|
|
+ //合并单元格
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void mergeCell(Field field,Cell cell){
|
|
|
|
|
+ ExcelPropertySupport excelPropertySupport = field.getAnnotation(ExcelPropertySupport.class);
|
|
|
|
|
+ if(excelPropertySupport==null||excelPropertySupport.merge()==null||!excelPropertySupport.merge().autoMerge()){
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
+ Sheet sheet = cell.getSheet();
|
|
|
|
|
+ ExcelCellMerge merge = excelPropertySupport.merge();
|
|
|
|
|
+ String cellValue = cell.getStringCellValue();
|
|
|
|
|
+ //不合并空值
|
|
|
|
|
+ if(StrUtil.isBlank(cellValue)&&!merge.mergeBlank()){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ int rowIndex = cell.getRowIndex();
|
|
|
|
|
+ //不与头部合并
|
|
|
|
|
+ if(rowIndex==2){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ Row row = sheet.getRow(rowIndex - 1);
|
|
|
|
|
+ Cell rowCell = row.getCell(cell.getColumnIndex());
|
|
|
|
|
+ String lastCellValue = rowCell.getStringCellValue();
|
|
|
|
|
+ if(StrUtil.isBlank(lastCellValue)&&!merge.mergeBlank()){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(StrUtil.equals(lastCellValue,cellValue)){
|
|
|
|
|
+ //单元格值相同,进行合并操作
|
|
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowIndex-1,rowIndex,cell.getColumnIndex(),cell.getColumnIndex()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void createDateColumn(Field field,Cell cell){
|
|
private void createDateColumn(Field field,Cell cell){
|