Easyexcel(7-自定义样式)

相关文章链接

  1. Easyexcel(1-注解使用)
  2. Easyexcel(2-文件读取)
  3. Easyexcel(3-文件导出)
  4. Easyexcel(4-模板文件)
  5. Easyexcel(5-自定义列宽)
  6. Easyexcel(6-单元格合并)
  7. Easyexcel(7-自定义样式)

注解

@ContentStyle

用于设置内容格式注解,可作用于类和字段上

  1. dataFormat:日期格式
  2. hidden:设置单元格使用此样式隐藏
  3. locked:设置单元格使用此样式锁定
  4. quotePrefix:在单元格前面增加`符号,数字或公式将以字符串形式展示
  5. horizontalAlignment:设置是否水平居中
  6. wrapped:设置文本是否应换行。将此标志设置为true通过在多行上显示使单元格中的所有内容可见
  7. verticalAlignment:设置是否垂直居中
  8. rotation:设置单元格中文本旋转角度。03版本的Excel旋转角度区间为-90°90°,07版本的Excel旋转角度区间为0°180°
  9. indent:设置单元格中缩进文本的空格数
  10. borderLeft:设置左边框的样式
  11. borderRight:设置右边框样式
  12. borderTop:设置上边框样式
  13. borderBottom:设置下边框样式
  14. leftBorderColor:设置左边框颜色
  15. rightBorderColor:设置右边框颜色
  16. topBorderColor:设置上边框颜色
  17. bottomBorderColor:设置下边框颜色
  18. fillPatternType:设置填充类型
  19. fillBackgroundColor:设置背景色
  20. fillForegroundColor:设置前景色
  21. shrinkToFit:设置自动单元格自动大小

@ContentFontStyle

用于设置单元格内容字体格式的注解,可作用于类和字段上

  1. fontName:字体名称
  2. fontHeightInPoints:字体高度
  3. italic:是否斜体
  4. strikeout:是否设置删除水平线
  5. color:字体颜色
  6. typeOffset:偏移量
  7. underline:下划线
  8. bold:是否加粗
  9. charset:编码格式

@HeadStyle

用于设置标题样式,可作用于类和字段上

  1. dataFormat:日期格式
  2. hidden:设置单元格使用此样式隐藏
  3. locked:设置单元格使用此样式锁定
  4. quotePrefix:在单元格前面增加`符号,数字或公式将以字符串形式展示
  5. horizontalAlignment:设置是否水平居中
  6. wrapped:设置文本是否应换行。将此标志设置为true通过在多行上显示使单元格中的所有内容可见
  7. verticalAlignment:设置是否垂直居中
  8. rotation:设置单元格中文本旋转角度。03版本的Excel旋转角度区间为-90°90°,07版本的Excel旋转角度区间为0°180°
  9. indent:设置单元格中缩进文本的空格数
  10. borderLeft:设置左边框的样式
  11. borderRight:设置右边框样式
  12. borderTop:设置上边框样式
  13. borderBottom:设置下边框样式
  14. leftBorderColor:设置左边框颜色
  15. rightBorderColor:设置右边框颜色
  16. topBorderColor:设置上边框颜色
  17. bottomBorderColor:设置下边框颜色
  18. fillPatternType:设置填充类型
  19. fillBackgroundColor:设置背景色
  20. fillForegroundColor:设置前景色
  21. shrinkToFit:设置自动单元格自动大小

@HeadFontStyle

用于定制标题字体格式,可作用于类和字段上

  1. fontName:设置字体名称
  2. fontHeightInPoints:设置字体高度
  3. italic:设置字体是否斜体
  4. strikeout:是否设置删除线
  5. color:设置字体颜色
  6. typeOffset:设置偏移量
  7. underline:设置下划线
  8. charset:设置字体编码
  9. bold:设置字体是否加粗

类方法

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

AbstractCellStyleStrategy

通过继承AbstractCellStyleStrategy类,实现其setHeadCellStyle和setContentCellStyle方法可以自定义设置表头和单元格内容样式

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);
        }
    }

    /**
     * 设置表头样式
     */
    protected void setHeadCellStyle(CellWriteHandlerContext context) {
   
        setHeadCellStyle(context.getCell(), context.getHeadData(), context.getRelativeRowIndex());
    }

    /**
     * 设置表头样式
     */
    protected void setHeadCellStyle(Cell cell, Head head, Integer relativeRowIndex) {
   
        throw new UnsupportedOperationException("Custom styles must override the setHeadCellStyle method.");
    }

    /**
     * 设置单元格内容样式
     */
    protected void setContentCellStyle(CellWriteHandlerContext context) {
   
        setContentCellStyle(context.getCell(), context.getHeadData(), context.getRelativeRowIndex());
    }

    /**
     * 设置单元格内容样式
     */
    protected void setContentCellStyle(Cell cell, Head head, Integer relativeRowIndex) {
   
        throw new 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值