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