mirror of https://github.com/alibaba/easyexcel
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.0 KiB
74 lines
2.0 KiB
package com.alibaba.excel.write.style; |
|
|
|
import com.alibaba.excel.constant.OrderConstant; |
|
import com.alibaba.excel.metadata.Head; |
|
import com.alibaba.excel.write.handler.CellWriteHandler; |
|
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext; |
|
|
|
import org.apache.poi.ss.usermodel.Cell; |
|
|
|
/** |
|
* Cell style strategy |
|
* |
|
* @author Jiaju Zhuang |
|
*/ |
|
public abstract class AbstractCellStyleStrategy implements CellWriteHandler { |
|
|
|
@Override |
|
public int order() { |
|
return OrderConstant.DEFINE_STYLE; |
|
} |
|
|
|
@Override |
|
public void afterCellDispose(CellWriteHandlerContext context) { |
|
if (context.getHead() == null) { |
|
return; |
|
} |
|
if (context.getHead()) { |
|
setHeadCellStyle(context); |
|
} else { |
|
setContentCellStyle(context); |
|
} |
|
} |
|
|
|
/** |
|
* Sets the cell style of header |
|
* |
|
* @param context |
|
*/ |
|
protected void setHeadCellStyle(CellWriteHandlerContext context) { |
|
setHeadCellStyle(context.getCell(), context.getHeadData(), context.getRelativeRowIndex()); |
|
} |
|
|
|
/** |
|
* Sets the cell style of header |
|
* |
|
* @param cell |
|
* @param head |
|
* @param relativeRowIndex |
|
*/ |
|
protected void setHeadCellStyle(Cell cell, Head head, Integer relativeRowIndex) { |
|
throw new UnsupportedOperationException("Custom styles must override the setHeadCellStyle method."); |
|
} |
|
|
|
/** |
|
* Sets the cell style of content |
|
* |
|
* @param context |
|
*/ |
|
protected void setContentCellStyle(CellWriteHandlerContext context) { |
|
setContentCellStyle(context.getCell(), context.getHeadData(), context.getRelativeRowIndex()); |
|
} |
|
|
|
/** |
|
* Sets the cell style of content |
|
* |
|
* @param cell |
|
* @param head |
|
* @param relativeRowIndex |
|
*/ |
|
protected void setContentCellStyle(Cell cell, Head head, Integer relativeRowIndex) { |
|
throw new UnsupportedOperationException("Custom styles must override the setContentCellStyle method."); |
|
} |
|
|
|
}
|
|
|