EasyExcel自定义头问题和合并单元格问题

自定义不显示头内容

将头部内容用空格代替,切记空格采用1212的形式 例如下
easyExcel 的默认合并方式是通过头部value 值是否相同进行判断的则使用这种方式可以将头部内容变成空的
@Data
@ContentRowHeight(17)
public class CostReportInfoDto {
   @ApiModelProperty("1月")
   @ExcelProperty(index=2,value = " ")
   private String oneMonth;
   @ApiModelProperty("2月")
   @ExcelProperty(index=3,value = "  ")
   private String twoMonth;
   @ApiModelProperty("3月")
   @ExcelProperty(index=4,value = " ")
   private String threeMonth;
   @ApiModelProperty("4月")
   @ExcelProperty(index=5,value = "  ")
   private String fourMonth;
   @ApiModelProperty("5月")
   @ExcelProperty(index=6,value = " ")
   private String fiveMonth;
   @ApiModelProperty("6月")
   @ExcelProperty(index=7,value = "  ")
   private String sixMonth;
   @ApiModelProperty("7月")
   @ExcelProperty(index=8,value = " ")
   private String sevenMonth;
   @ApiModelProperty("8月")
   @ExcelProperty(index=9,value = "  ")
   private String eightMonth;
   @ApiModelProperty("9月")
   @ExcelProperty(index=10,value = " ")
   private String nineMonth;
   @ApiModelProperty("10月")
   @ExcelProperty(index=11,value = "  ")
   private String tenMonth;
   @ApiModelProperty("11月")
   @ExcelProperty(index=12,value = " ")
   private String elevenMonth;
   @ApiModelProperty("12月")
   @ExcelProperty(index=13,value = "  ")
   private String twelve;
   @ApiModelProperty("总计")
   @ExcelProperty(index=14,value = "   ")
   private String total;
}

还不够
已经给easyExcel github上提出 单元格合并问题了。

等不及的看这里

1 WriteBasicParameter 此类中加入hook 函数 set get 方法记得写
  private WriteHandler endHandler = null;
 2 ExcelWriterBuilder 此类中加入添加register 方法
  public ExcelWriterBuilder registerWriteEndHandler(WriteHandler writeHandler) {
        writeWorkbook.setEndHandler(writeHandler);
        return this;
    }
  3 WriteContextImpl 此类构造方法中将endHandler 从WriteBasicParameter 中取出
     private WriteHandler endHandler;
   public WriteContextImpl(WriteWorkbook writeWorkbook) {
        this.endHandler = writeWorkbook.getEndHandler();
        .....
   同时提供get 方法
    @Override
   public  WriteHandler getEnd(){
        return this.endHandler;
   }
   以及接口中的方法
   WriteContext
   /**
     * 获取excel绘画结束的后需要执行的hanlder
     * @return
     */
    WriteHandler getEnd();
    4 ExcelBuilderImpl 中添加
     @Override
    public void addContent(List data, WriteSheet writeSheet, WriteTable writeTable) {
        try {
            context.currentSheet(writeSheet);
            context.currentTable(writeTable);
            WriteHandler end = context.getEnd();
            doAddContent(data);
            if(null!=end){
                ((CellWriteHandler)end).beforeCellCreate(context.writeSheetHolder(),context.writeTableHolder(),null,null,0,false);
                ((CellWriteHandler)end).afterCellCreate(context.writeSheetHolder(),context.writeTableHolder(),null,null,null,0,false);
            }
        } catch (RuntimeException e) {
            finish();
            throw e;
        } catch (Throwable e) {
            finish();
            throw new ExcelGenerateException(e);
        }
    }

搞定

在这里插入图片描述
拿取我自己写的

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值