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自定义头问题和合并单元格问题》
已经给easyExcel github上提出 单元格合并问题了。
《EasyExcel自定义头问题和合并单元格问题》

等不及的看这里

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

搞定

《EasyExcel自定义头问题和合并单元格问题》
拿取我自己写的

    原文作者:Laughable Man
    原文地址: https://blog.csdn.net/weixin_43897412/article/details/106616657
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞