17 changed files with 969 additions and 9 deletions
@ -0,0 +1,167 @@ |
|||||
|
package tech.abc.platform.elasticsearch.entity; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.*; |
||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
import lombok.experimental.Accessors; |
||||
|
import tech.abc.platform.common.base.BaseEntity; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
/** |
||||
|
* 实体类 |
||||
|
* |
||||
|
* @author ZHB |
||||
|
* @date 2024-05-08 |
||||
|
* |
||||
|
*/ |
||||
|
@Data |
||||
|
@TableName("pmg_supplier_products") |
||||
|
@JsonIgnoreProperties(ignoreUnknown=true) |
||||
|
|
||||
|
public class SupplierProductsDTO { |
||||
|
|
||||
|
/** |
||||
|
* 供应商id |
||||
|
*/ |
||||
|
@TableField("supplier_information_id") |
||||
|
@JsonProperty("supplier_information_id") |
||||
|
private String supplierInformationId; |
||||
|
|
||||
|
/** |
||||
|
* 厂商产品型号id |
||||
|
*/ |
||||
|
@TableField("model_id") |
||||
|
@JsonProperty("model_id") |
||||
|
private String modelId; |
||||
|
|
||||
|
/** |
||||
|
* 个人产品规格 |
||||
|
*/ |
||||
|
@TableField("product_specifications") |
||||
|
@JsonProperty("product_specifications") |
||||
|
private String productSpecifications; |
||||
|
|
||||
|
/** |
||||
|
* 产品名称 |
||||
|
*/ |
||||
|
@TableField("product_name") |
||||
|
@JsonProperty("product_name") |
||||
|
private String productName; |
||||
|
|
||||
|
/** |
||||
|
* 产品标识(型号) |
||||
|
*/ |
||||
|
@TableField("product_identity") |
||||
|
@JsonProperty("product_identity") |
||||
|
private String productIdentity; |
||||
|
|
||||
|
/** |
||||
|
* 产品价格 |
||||
|
*/ |
||||
|
@TableField(value="product_price",updateStrategy= FieldStrategy.IGNORED) |
||||
|
@JsonProperty("product_price") |
||||
|
private BigDecimal productPrice; |
||||
|
|
||||
|
/** |
||||
|
* 信息来源 |
||||
|
*/ |
||||
|
@TableField("source_information") |
||||
|
@JsonProperty("source_information") |
||||
|
private String sourceInformation; |
||||
|
|
||||
|
/** |
||||
|
* 备注 |
||||
|
*/ |
||||
|
@TableField("remarks") |
||||
|
@JsonProperty("remarks") |
||||
|
private String remarks; |
||||
|
/** |
||||
|
* 产品图片 |
||||
|
*/ |
||||
|
@TableField("image") |
||||
|
@JsonProperty("image") |
||||
|
private String image; |
||||
|
|
||||
|
/** |
||||
|
* 产品品牌 |
||||
|
*/ |
||||
|
@TableField("brand") |
||||
|
@JsonProperty("brand") |
||||
|
private String brand; |
||||
|
|
||||
|
/** |
||||
|
* 产品单位*/ |
||||
|
@TableField("unit") |
||||
|
@JsonProperty("unit") |
||||
|
private String unit; |
||||
|
|
||||
|
/** |
||||
|
* 除税价格 |
||||
|
*/ |
||||
|
@TableField("ex_tax_price") |
||||
|
@JsonProperty("ex_tax_price") |
||||
|
private BigDecimal exTaxPrice; |
||||
|
|
||||
|
/** |
||||
|
* 税率 |
||||
|
*/ |
||||
|
@TableField("taxrate") |
||||
|
@JsonProperty("taxrate") |
||||
|
private BigDecimal taxrate; |
||||
|
/** |
||||
|
* 分类id |
||||
|
*/ |
||||
|
@TableField("category_id") |
||||
|
@JsonProperty("category_id") |
||||
|
private String categoryId; |
||||
|
|
||||
|
/** |
||||
|
* 逻辑删除 |
||||
|
*/ |
||||
|
@TableField(value = "delete_flag", fill = FieldFill.INSERT) |
||||
|
@TableLogic |
||||
|
@JsonProperty("delete_flag") |
||||
|
protected String deleteFlag; |
||||
|
/** |
||||
|
* 创建人标识 |
||||
|
*/ |
||||
|
|
||||
|
@TableField(value = "create_id", fill = FieldFill.INSERT) |
||||
|
@JsonProperty("create_id") |
||||
|
private String createId; |
||||
|
|
||||
|
/** |
||||
|
* 创建时间 |
||||
|
*/ |
||||
|
@TableField(value = "create_time", fill = FieldFill.INSERT) |
||||
|
@JsonProperty("create_time") |
||||
|
private String createTime; |
||||
|
|
||||
|
/** |
||||
|
* 更新人标识 |
||||
|
*/ |
||||
|
|
||||
|
@TableField(value = "update_id", fill = FieldFill.INSERT_UPDATE) |
||||
|
@JsonProperty("update_id") |
||||
|
private String updateId; |
||||
|
|
||||
|
/** |
||||
|
* 更新时间 |
||||
|
*/ |
||||
|
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) |
||||
|
@JsonProperty("update_time") |
||||
|
private String updateTime; |
||||
|
|
||||
|
/** |
||||
|
* 版本 |
||||
|
*/ |
||||
|
|
||||
|
@TableField(value = "version", fill = FieldFill.INSERT) |
||||
|
@JsonProperty("version") |
||||
|
private Integer version; |
||||
|
/********非库表存储属性*****/ |
||||
|
} |
@ -0,0 +1,231 @@ |
|||||
|
package tech.abc.platform.common.extension; |
||||
|
|
||||
|
import cn.hutool.core.util.StrUtil; |
||||
|
import com.alibaba.excel.EasyExcel; |
||||
|
import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder; |
||||
|
|
||||
|
import org.springframework.util.CollectionUtils; |
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
import javax.validation.constraints.NotEmpty; |
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import java.io.IOException; |
||||
|
import java.net.URLEncoder; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* EasyExcel工具类 |
||||
|
*/ |
||||
|
public class EasyExcelUtils { |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 注入的具有排序功能的handle |
||||
|
*/ |
||||
|
// private static final SortRowWriteHandler SORT_ROW_WRITE_HANDLER = new SortRowWriteHandler();
|
||||
|
|
||||
|
/** |
||||
|
* 导出excel-按指定顺序 |
||||
|
* |
||||
|
* @param <T> 类(必须是小写,并遵守阿里开发规范) |
||||
|
* @param list 列表数据 |
||||
|
* @param fileName 文件名称 |
||||
|
* @param useDefaultStyle 是否使用默认样式 |
||||
|
* @param response 响应 |
||||
|
*/ |
||||
|
public static <T> Map<String, Object> exportExcelInclude(List<T> list, String fileName,Boolean useDefaultStyle, HttpServletResponse response) throws IOException { |
||||
|
Map<String, Object> resultMap = new HashMap<>(); |
||||
|
if (list.size() == 0) { |
||||
|
resultMap.put("msg", "数据长度为空"); |
||||
|
resultMap.put("result", -1); |
||||
|
return resultMap; |
||||
|
} |
||||
|
|
||||
|
Class<?> clazz = list.get(0).getClass(); |
||||
|
|
||||
|
/*定义编码,格式*/ |
||||
|
response.setContentType("application/vnd.ms-excel"); |
||||
|
response.setCharacterEncoding("utf-8"); |
||||
|
String exportFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20"); |
||||
|
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + exportFileName + ".xlsx"); |
||||
|
response.setHeader("filename", exportFileName + ".xlsx"); |
||||
|
response.setHeader("Access-Control-Expose-Headers", "filename"); |
||||
|
/** |
||||
|
* .head(head(headNameList)) |
||||
|
* 改行代码不可以用ExcelWriterSheetBuilder类型的变量单独写,否则会包错:表头长度与字段列表长度不符 |
||||
|
*/ |
||||
|
/*导出表格*/ |
||||
|
ExcelWriterSheetBuilder excelWriterSheetBuilder = EasyExcel.write(response.getOutputStream(), clazz) |
||||
|
.useDefaultStyle(useDefaultStyle) |
||||
|
.sheet(fileName); |
||||
|
excelWriterSheetBuilder.doWrite(list); |
||||
|
|
||||
|
resultMap.put("msg", "excel export success"); |
||||
|
resultMap.put("result", 0); |
||||
|
return resultMap; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 导出excel-默认顺序 |
||||
|
* |
||||
|
* @param <T> 类(必须是小写,并遵守阿里开发规范) |
||||
|
* @param list 列表数据 |
||||
|
* @param fileName 文件名称 |
||||
|
* @param useDefaultStyle 是否使用默认样式 |
||||
|
* @param response 响应 |
||||
|
* @param headNameList |
||||
|
* @param columnList 设置列字段(必须是小写) |
||||
|
*/ |
||||
|
public static <T> Map<String, Object> exportExcelInclude(List<T> list, String fileName,Boolean useDefaultStyle, HttpServletResponse response, List<String> columnList, List<String> headNameList) throws IOException { |
||||
|
Map<String, Object> resultMap = new HashMap<>(); |
||||
|
if (list.size() == 0) { |
||||
|
resultMap.put("msg", "数据长度为空"); |
||||
|
resultMap.put("result", -1); |
||||
|
return resultMap; |
||||
|
} |
||||
|
|
||||
|
if (CollectionUtils.isEmpty(headNameList)) { |
||||
|
/*设置表头*/ |
||||
|
resultMap.put("msg", "表头长度为空"); |
||||
|
resultMap.put("result", -2); |
||||
|
return resultMap; |
||||
|
} |
||||
|
|
||||
|
if (CollectionUtils.isEmpty(columnList)) { |
||||
|
/*设置列字段*/ |
||||
|
resultMap.put("msg", "列字段长度为空"); |
||||
|
resultMap.put("result", -3); |
||||
|
return resultMap; |
||||
|
} |
||||
|
|
||||
|
Class<?> clazz = list.get(0).getClass(); |
||||
|
|
||||
|
/*定义编码,格式*/ |
||||
|
response.setContentType("application/vnd.ms-excel"); |
||||
|
response.setCharacterEncoding("utf-8"); |
||||
|
String exportFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20"); |
||||
|
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + exportFileName + ".xlsx"); |
||||
|
response.setHeader("filename", exportFileName + ".xlsx"); |
||||
|
response.setHeader("Access-Control-Expose-Headers", "filename"); |
||||
|
/** |
||||
|
* .head(head(headNameList)) |
||||
|
* 改行代码不可以用ExcelWriterSheetBuilder类型的变量单独写,否则会包错:表头长度与字段列表长度不符 |
||||
|
*/ |
||||
|
/*导出表格*/ |
||||
|
ExcelWriterSheetBuilder excelWriterSheetBuilder = EasyExcel.write(response.getOutputStream(), clazz) |
||||
|
.head(head(headNameList)) |
||||
|
/*设置列字段(会按顺序)*/ |
||||
|
.includeColumnFiledNames(columnList) |
||||
|
/*注入的具有排序功能的handle*/ |
||||
|
// .registerWriteHandler(SORT_ROW_WRITE_HANDLER)
|
||||
|
.useDefaultStyle(useDefaultStyle) |
||||
|
.sheet(fileName); |
||||
|
excelWriterSheetBuilder.doWrite(list); |
||||
|
|
||||
|
resultMap.put("msg", "excel export success"); |
||||
|
resultMap.put("result", 0); |
||||
|
return resultMap; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 支持动态头,行列合并导出 |
||||
|
* |
||||
|
* @param response web响应 |
||||
|
* @param headList 动态头 |
||||
|
* @param dataList 数据列表 |
||||
|
* @param columnMergeHandler 注入列合并 |
||||
|
* @param rowMergeHandler 注入行合并 |
||||
|
* @throws IOException |
||||
|
*/ |
||||
|
public static Map<String, Object> writeDynamicExcel(HttpServletResponse response, @NotEmpty List<List<String>> headList, @NotEmpty List<List<Object>> dataList, @NotNull ExcelColumnMergeHandler columnMergeHandler,@NotNull ExcelRowMergeHandler rowMergeHandler) throws IOException { |
||||
|
Map<String, Object> resultMap = new HashMap<>(); |
||||
|
if (dataList.size() == 0) { |
||||
|
resultMap.put("msg", "数据长度为空"); |
||||
|
resultMap.put("result", -1); |
||||
|
return resultMap; |
||||
|
} |
||||
|
|
||||
|
if (CollectionUtils.isEmpty(headList)) { |
||||
|
/*设置表头*/ |
||||
|
resultMap.put("msg", "表头长度为空"); |
||||
|
resultMap.put("result", -2); |
||||
|
return resultMap; |
||||
|
} |
||||
|
|
||||
|
if (columnMergeHandler == null || rowMergeHandler == null) { |
||||
|
/*设置列字段*/ |
||||
|
resultMap.put("msg", "行列处理器为空"); |
||||
|
resultMap.put("result", -3); |
||||
|
return resultMap; |
||||
|
} |
||||
|
|
||||
|
EasyExcel.write(response.getOutputStream()) |
||||
|
// 设置动态头
|
||||
|
.head(headList) |
||||
|
.sheet("模板") |
||||
|
/*注入列合并*/ |
||||
|
.registerWriteHandler(columnMergeHandler) |
||||
|
/*注入行合并*/ |
||||
|
.registerWriteHandler(rowMergeHandler) |
||||
|
/*传需要写入的数据,类型List<List<Object>>*/ |
||||
|
.doWrite(dataList); |
||||
|
|
||||
|
resultMap.put("msg", "excel export success"); |
||||
|
resultMap.put("result", 0); |
||||
|
return resultMap; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 支持动态头导出 |
||||
|
* |
||||
|
* @param response web响应 |
||||
|
* @param headList 动态头 |
||||
|
* @param dataList 数据列表 |
||||
|
* @throws IOException |
||||
|
*/ |
||||
|
public static void writeDynamicExcel(HttpServletResponse response,List<List<String>> headList, List<List<Object>> dataList) throws IOException { |
||||
|
EasyExcel.write(response.getOutputStream()) |
||||
|
// 设置动态头
|
||||
|
.head(headList) |
||||
|
.sheet("模板") |
||||
|
/*传需要写入的数据,类型List<List<Object>>*/ |
||||
|
.doWrite(dataList); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 设置Excel头 |
||||
|
* |
||||
|
* @param headList Excel头信息 |
||||
|
* @return |
||||
|
*/ |
||||
|
public static List<List<String>> head(List<String> headList) { |
||||
|
List<List<String>> list = new ArrayList<>(); |
||||
|
for (String value : headList) { |
||||
|
List<String> head = new ArrayList<>(); |
||||
|
head.add(value); |
||||
|
list.add(head); |
||||
|
} |
||||
|
return list; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Excel头对应的字段转换小写 |
||||
|
* |
||||
|
* @param ColumnListTemp Excel字段 |
||||
|
* @return |
||||
|
*/ |
||||
|
public static List<String> castLowerCase(List<String> ColumnListTemp) { |
||||
|
List<String> ColumnList = new ArrayList<>(); |
||||
|
for (String name : ColumnListTemp) { |
||||
|
ColumnList.add(StrUtil.lowerFirst(name)); |
||||
|
} |
||||
|
return ColumnList; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,108 @@ |
|||||
|
package tech.abc.platform.common.extension; |
||||
|
|
||||
|
import com.alibaba.excel.metadata.Head; |
||||
|
import com.alibaba.excel.metadata.data.WriteCellData; |
||||
|
import com.alibaba.excel.write.handler.CellWriteHandler; |
||||
|
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; |
||||
|
import com.alibaba.excel.write.metadata.holder.WriteTableHolder; |
||||
|
import lombok.Data; |
||||
|
import org.apache.poi.ss.usermodel.Cell; |
||||
|
import org.apache.poi.ss.usermodel.CellType; |
||||
|
import org.apache.poi.ss.usermodel.Row; |
||||
|
import org.apache.poi.ss.usermodel.Sheet; |
||||
|
import org.apache.poi.ss.util.CellRangeAddress; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/*** |
||||
|
* 列合并处理器 |
||||
|
* |
||||
|
*/ |
||||
|
@Data |
||||
|
public class ExcelColumnMergeHandler implements CellWriteHandler { |
||||
|
/** |
||||
|
* 合并字段的下标,如new int[]{0,1,2,3,4,10},0-4合并,10合并 |
||||
|
*/ |
||||
|
private int[] mergeColumnIndex; |
||||
|
/** |
||||
|
* 从第几行开始合并,如果表头占两行,这个数字就是2 |
||||
|
*/ |
||||
|
private int mergeRowIndex; |
||||
|
|
||||
|
public ExcelColumnMergeHandler() { |
||||
|
} |
||||
|
|
||||
|
public ExcelColumnMergeHandler(int mergeRowIndex, int[] mergeColumnIndex) { |
||||
|
this.mergeRowIndex = mergeRowIndex; |
||||
|
this.mergeColumnIndex = mergeColumnIndex; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, |
||||
|
Head head, Integer integer, Integer integer1, Boolean aBoolean) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell, |
||||
|
Head head, Integer integer, Boolean aBoolean) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, |
||||
|
WriteCellData cellData, Cell cell, Head head, Integer integer, Boolean aBoolean) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, |
||||
|
List<WriteCellData<?>> list, Cell cell, Head head, Integer integer, Boolean aBoolean) { |
||||
|
//当前行
|
||||
|
int curRowIndex = cell.getRowIndex(); |
||||
|
//当前列
|
||||
|
int curColIndex = cell.getColumnIndex(); |
||||
|
|
||||
|
if (curRowIndex > mergeRowIndex) { |
||||
|
for (int i = 0; i < mergeColumnIndex.length; i++) { |
||||
|
if (curColIndex == mergeColumnIndex[i]) { |
||||
|
mergeWithPrevRow(writeSheetHolder, cell, curRowIndex, curColIndex); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void mergeWithPrevRow(WriteSheetHolder writeSheetHolder, Cell cell, int curRowIndex, int curColIndex) { |
||||
|
//获取当前行的当前列的数据和上一行的当前列列数据,通过上一行数据是否相同进行合并
|
||||
|
Object curData = cell.getCellTypeEnum() == CellType.STRING ? cell.getStringCellValue() : |
||||
|
cell.getNumericCellValue(); |
||||
|
Cell preCell = cell.getSheet().getRow(curRowIndex - 1).getCell(curColIndex); |
||||
|
Object preData = preCell.getCellTypeEnum() == CellType.STRING ? preCell.getStringCellValue() : |
||||
|
preCell.getNumericCellValue(); |
||||
|
// 比较当前行的第一列的单元格与上一行是否相同,相同合并当前单元格与上一行
|
||||
|
//
|
||||
|
if (curData.equals(preData)) { |
||||
|
Sheet sheet = writeSheetHolder.getSheet(); |
||||
|
List<CellRangeAddress> mergeRegions = sheet.getMergedRegions(); |
||||
|
boolean isMerged = false; |
||||
|
for (int i = 0; i < mergeRegions.size() && !isMerged; i++) { |
||||
|
CellRangeAddress cellRangeAddr = mergeRegions.get(i); |
||||
|
// 若上一个单元格已经被合并,则先移出原有的合并单元,再重新添加合并单元
|
||||
|
if (cellRangeAddr.isInRange(curRowIndex - 1, curColIndex)) { |
||||
|
sheet.removeMergedRegion(i); |
||||
|
cellRangeAddr.setLastRow(curRowIndex); |
||||
|
sheet.addMergedRegion(cellRangeAddr); |
||||
|
isMerged = true; |
||||
|
} |
||||
|
} |
||||
|
// 若上一个单元格未被合并,则新增合并单元
|
||||
|
if (!isMerged) { |
||||
|
CellRangeAddress cellRangeAddress = new CellRangeAddress(curRowIndex - 1, curRowIndex, curColIndex, |
||||
|
curColIndex); |
||||
|
sheet.addMergedRegion(cellRangeAddress); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
@ -0,0 +1,87 @@ |
|||||
|
package tech.abc.platform.common.extension; |
||||
|
|
||||
|
import com.alibaba.excel.metadata.Head; |
||||
|
import com.alibaba.excel.metadata.data.WriteCellData; |
||||
|
import com.alibaba.excel.write.handler.CellWriteHandler; |
||||
|
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; |
||||
|
import com.alibaba.excel.write.metadata.holder.WriteTableHolder; |
||||
|
import org.apache.poi.ss.usermodel.Cell; |
||||
|
import org.apache.poi.ss.usermodel.Row; |
||||
|
import org.apache.poi.ss.usermodel.Sheet; |
||||
|
import org.apache.poi.ss.util.CellRangeAddress; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 行合并处理器 |
||||
|
* |
||||
|
*/ |
||||
|
public class ExcelRowMergeHandler implements CellWriteHandler { |
||||
|
private static final String KEY ="%s-%s"; |
||||
|
//所有的合并信息都存在了这个map里面
|
||||
|
Map<String, Integer> mergeInfo = new HashMap<>(); |
||||
|
|
||||
|
public ExcelRowMergeHandler() { |
||||
|
} |
||||
|
public ExcelRowMergeHandler(Map<String, Integer> mergeInfo) { |
||||
|
this.mergeInfo = mergeInfo; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Head head, Integer integer, Integer integer1, Boolean aBoolean) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell, Head head, Integer integer, Boolean aBoolean) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, WriteCellData cellData, Cell cell, Head head, Integer integer, Boolean aBoolean) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<WriteCellData<?>> list, Cell cell, Head head, Integer integer, Boolean aBoolean) { |
||||
|
//当前行
|
||||
|
int curRowIndex = cell.getRowIndex(); |
||||
|
//当前列
|
||||
|
int curColIndex = cell.getColumnIndex(); |
||||
|
|
||||
|
Integer num = mergeInfo.get(String.format(KEY, curRowIndex, curColIndex)); |
||||
|
if(null != num){ |
||||
|
// 合并最后一行 ,列
|
||||
|
mergeWithPrevCol(writeSheetHolder, cell, curRowIndex, curColIndex,num); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void mergeWithPrevCol(WriteSheetHolder writeSheetHolder, Cell cell, int curRowIndex, int curColIndex, int num) { |
||||
|
Sheet sheet = writeSheetHolder.getSheet(); |
||||
|
CellRangeAddress cellRangeAddress = new CellRangeAddress(curRowIndex, curRowIndex, curColIndex, curColIndex + num); |
||||
|
sheet.addMergedRegion(cellRangeAddress); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 添加合并行 |
||||
|
* 比如参数:(3,0,2) |
||||
|
* 从第三行的地0列开始向右合并2格 |
||||
|
* 这样,第三行的地0列到第2列就会合并 |
||||
|
* |
||||
|
* 注意: |
||||
|
* 合并不能冲突,如果合并到已经被合并的地方会报一个POI错误 |
||||
|
* (java.lang.IllegalStateException: Cannot add merged region B3:B6 to sheet because it overlaps with an existing merged region (A6:C6).) |
||||
|
* |
||||
|
* @param curRowIndex 当前行: 需要合并的哪一行(一般用数据List的“index”+“表头的行数”,表头站的行数是1就+1,是2就+2) |
||||
|
* @param curColIndex 合并开始列:从第几行开始合并 |
||||
|
* @param num 合并列的数量:从第curColIndex行开始,向右合并多少格 |
||||
|
*/ |
||||
|
public void add (int curRowIndex, int curColIndex , int num){ |
||||
|
mergeInfo.put(String.format(KEY, curRowIndex, curColIndex),num); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
Loading…
Reference in new issue