【EasyExcel】导出excel扩展支持自定义颜色
/**
* 自定义单元格背景颜色样式处理器,可以扩展其他的样式
*/
public class StyleHandler extends AbstractRowWriteHandler {
/**
* sheet页名称列表
*/
private List<String> sheetNameList;
/**
* 样式信息
*/
private List<StyleModel> cellStyleList = new ArrayList<>();
/**
* 自定义样式适配器构造方法
*
* @param cellStyleList 样式信息
*/
public StyleHandler(List<StyleModel> cellStyleList) {
if (CollectionUtil.isEmpty(cellStyleList)) {
return;
}
cellStyleList = cellStyleList.stream().filter(x -> x != null
//判断sheet名称KEY是否存在
&& StrUtil.isNotBlank(x.getSheetName())
//判断背景颜色KEY是否存在
&& (x.getBackgroundColor() == null || x.getBackgroundColor() instanceof IndexedColors
|| x.getBackgroundColor() instanceof XSSFColor)
).collect(Collectors.toList());
this.cellStyleList = cellStyleList;
sheetNameList = this.cellStyleList.stream().map(x -> x.getSheetName()).distinct().collect(Collectors.toList());
}
/**
* 这个方法是重点,通过重写该方法实现样式的添加
* @param writeSheetHolder
* @param writeTableHolder
* @param row
* @param relativeRowIndex
* @param isHead
*/
