一、背景
Easy Excel 导出,发现excel 存在大量的绿色角标,很影响美观,如果个人使用可以设置wps或office 忽略检测警告,
但是我是对业主的,所以这一方式对我不适用,只能通过代码的方式解决.
二、实现
通过以下创建一个 ExcelWriter ,实现去绿色角标的关键是 使用easyExcel 自带的拦截器.
ExcelWriter excelWriter = EasyExcel.write(byteArrayOutputStream).registerWriteHandler(new CustomCellWriteHandler()).withTemplate(resource.getInputStream()).build())
拦截器写法
package me.zhengjie.modules.util; import cn.hutool.core.util.NumberUtil; import com.alibaba.excel.enums.CellDataTypeEnum; import com.alibaba.excel.metadata.Head; import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.write.handler.CellWriteHandler; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; import com.alibaba.excel.write.metadata.holder.WriteTableHolder; import org.apache.poi.ss.usermodel.Cell; public class CustomCellWriteHandler implements CellWriteHandler { @Override public void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, WriteCellData<?> cellData, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) { // 数据为纯数字时,设置单元格类型为数字 String dataValue = cellData.getStringValue(); if (NumberUtil.isNumber(dataValue)) { cellData.setType(CellDataTypeEnum.NUMBER); cellData.setNumberValue(NumberUtil.toBigDecimal(dataValue)); } } }
原先截图是这样
使用自定义拦截器后(干干净净)
三、参考博客
https://easyexcel.opensource.alibaba.com/docs/current/quickstart/write#%E5%AE%9A%E4%B9%89%E6%8B%A6%E6%88%AA%E5%99%A8
标签:cellData,excel,Excel,alibaba,write,角标,Easy,import,com From: https://www.cnblogs.com/lcaiqin/p/17789414.html