当前位置: 首页 > news >正文

easyexcel多级表头导出各级设置样式(继承HorizontalCellStyleStrategy实现)

easyexcel多级表头导出各级设置样式(继承HorizontalCellStyleStrategy实现)

package com.example.wxmessage.entity;import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;/*** @author chenyuhuan* @ClassName CellStyleStrategy.java* @Description TODO* @createTime 2023年12月01日*/
public class CellStyleStrategy extends HorizontalCellStyleStrategy {private final WriteCellStyle headWriteCellStyle;public CellStyleStrategy(WriteCellStyle headWriteCellStyle) {this.headWriteCellStyle = headWriteCellStyle;}@Overrideprotected void setHeadCellStyle(CellWriteHandlerContext context) {// 根据行索引为不同级别的表头应用不同样式if (context.getRowIndex() == 0) {headWriteCellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);} else if (context.getRowIndex() == 1) {headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);}if (stopProcessing(context)) {return;}WriteCellData<?> cellData = context.getFirstCellData();WriteCellStyle.merge(this.headWriteCellStyle, cellData.getOrCreateStyle());}
}###########################调用###############################EasyExcel.write(response.getOutputStream(), ParamWorkdaysExportExcel.class).registerWriteHandler(new CellStyleStrategy(new WriteCellStyle())).sheet("模板").doWrite(data);

image.png1701659747655.png

http://www.lryc.cn/news/252428.html

相关文章:

  • QMLfor python pyside6
  • 几何教学工具 Sketchpad几何画板 mac软件特色
  • 华清远见嵌入式学习——C++——作业5
  • Java中的类与类之间的关系
  • 全新仿某度文库网站源码/在线文库源码/文档分享平台网站源码/仿某度文库PHP源码
  • HTTPS的安全问题及应对方案
  • TensorRT-LLM保姆级教程(一)-快速入门
  • 使用Redis构建简易社交网站(3)-状态与信息流
  • Python,非二进制的霍夫曼编码
  • 详解—[C++数据结构]—红黑树
  • 甘草书店记:6# 2023年10月31日 星期二 「梦想从来不是一夜之间实现的」
  • 基于Java SSM车辆租赁管理系统
  • 侯捷C++八部曲(一,面向对象)
  • 《数据库系统概论》学习笔记——王珊 萨师煊
  • 关于使用百度开发者平台处理语音朗读问题排查
  • 安全认证 | CISP和CISP-PTE的区别在哪里?
  • Unity3D 导出的apk进行混淆加固、保护与优化原理(防止反编译)
  • C语言扫雷小游戏
  • 用取样思想一探AIX上进程性能瓶颈
  • 分布式搜索引擎elasticsearch(二)
  • Tecplot绘制涡结构(Q准则)
  • Whisper
  • Android系统分析
  • 五、关闭三台虚拟机的防火墙和Selinux
  • 【从零开始学习Redis | 第六篇】爆改Setnx实现分布式锁
  • Kubernetes学习笔记-Part.05 基础环境准备
  • 语义分割 DeepLab V1网络学习笔记 (附代码)
  • java设计模式学习之【建造者模式】
  • Spring Boot中的RabbitMQ死信队列魔法:从异常到延迟,一网打尽【RabbitMQ实战 一】
  • nrm : 镜像源工具npm镜像切换