Browse Source

修复填充调用横向样式策略报错 [Issue #1651]

pull/2077/head
Jiaju Zhuang 3 years ago
parent
commit
bc4ba98d58
  1. 34
      src/main/java/com/alibaba/excel/write/style/HorizontalCellStyleStrategy.java
  2. 1
      update.md

34
src/main/java/com/alibaba/excel/write/style/HorizontalCellStyleStrategy.java

@ -2,7 +2,7 @@ package com.alibaba.excel.write.style;
import java.util.List;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.util.ListUtils;
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
@ -14,7 +14,7 @@ import org.apache.commons.collections4.CollectionUtils;
*
* @author Jiaju Zhuang
*/
public class HorizontalCellStyleStrategy extends AbstractVerticalCellStyleStrategy {
public class HorizontalCellStyleStrategy extends AbstractCellStyleStrategy {
private WriteCellStyle headWriteCellStyle;
private List<WriteCellStyle> contentWriteCellStyleList;
@ -33,16 +33,34 @@ public class HorizontalCellStyleStrategy extends AbstractVerticalCellStyleStrate
}
@Override
protected WriteCellStyle headCellStyle(Head head) {
return headWriteCellStyle;
protected void setHeadCellStyle(CellWriteHandlerContext context) {
if (!continueProcessing(context) || headWriteCellStyle == null) {
return;
}
WriteCellData<?> cellData = context.getCellDataList().get(0);
cellData.setWriteCellStyle(headWriteCellStyle);
}
@Override
protected WriteCellStyle contentCellStyle(CellWriteHandlerContext context) {
if (CollectionUtils.isEmpty(contentWriteCellStyleList)) {
return null;
protected void setContentCellStyle(CellWriteHandlerContext context) {
if (!continueProcessing(context) || CollectionUtils.isEmpty(contentWriteCellStyleList)) {
return;
}
WriteCellData<?> cellData = context.getCellDataList().get(0);
if (context.getRelativeRowIndex() == null || context.getRelativeRowIndex() <= 0) {
cellData.setWriteCellStyle(contentWriteCellStyleList.get(0));
} else {
cellData.setWriteCellStyle(
contentWriteCellStyleList.get(context.getRelativeRowIndex() % contentWriteCellStyleList.size()));
}
}
protected boolean continueProcessing(CellWriteHandlerContext context) {
List<WriteCellData<?>> cellDataList = context.getCellDataList();
if (CollectionUtils.isEmpty(cellDataList) || cellDataList.size() > 1) {
return false;
}
return contentWriteCellStyleList.get(context.getRelativeRowIndex() % contentWriteCellStyleList.size());
return true;
}
}

1
update.md

@ -19,6 +19,7 @@
* 修改填充可能填充错误的bug [Issue #2035](https://github.com/alibaba/easyexcel/issues/2035)
* 修复无对象读 返回map的size可能会头的size不一致 [Issue #2014](https://github.com/alibaba/easyexcel/issues/2014)
* 修复合并头可能异常的bug [Issue #1662](https://github.com/alibaba/easyexcel/issues/1662)
* 修复填充调用横向样式策略报错 [Issue #1651](https://github.com/alibaba/easyexcel/issues/1651)
# 2.2.10

Loading…
Cancel
Save