使用 com.alibaba:easyexcel 导出excel文件时遇到的问题
创始人
2024-12-29 08:10:52
0

1.字符长度超出限制

java.lang.IllegalArgumentException: The maximum length of cell contents (text) is 32,767 characters

解决方案:

1. 把字符串截取前32767个字符
/**  * sqlText 字段导出 excel 时的转化器  */ public class SqlTextConverter implements Converter {     @Override     public WriteCellData convertToExcelData(WriteConverterContext context) throws Exception {         // 截取 SQL 语句前 32767 个字符         WriteCellData cellData = new WriteCellData<>();         String sqlText = context.getValue();         String splitSqlText = sqlText.substring(0,32767);         cellData.setData(splitSqlText);         cellData.setType(CellDataTypeEnum.STRING);         cellData.setStringValue(splitSqlText);         return cellData;     } }  

在实体类上加上注解

    @ExcelProperty(value = "SQL 语句", converter = SqlTextConverter.class)     @ColumnWidth(100)     private String sqlText; 
2.项目启动时统一修改最大长度
import org.apache.poi.ss.SpreadsheetVersion; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component;  import java.lang.reflect.Field;  /**  * 统一修改 excel 列最大长度  */ @Component public class ApplicationCommandLine implements CommandLineRunner {     @Override     public void run(String... args) throws Exception {         SpreadsheetVersion spreadsheetVersion = SpreadsheetVersion.EXCEL2007;         Field maxTextLength = spreadsheetVersion.getClass().getDeclaredField("_maxTextLength");         maxTextLength.setAccessible(true);         maxTextLength.set(spreadsheetVersion, Integer.MAX_VALUE);     } }  

相关内容

热门资讯

关于透视!德州真人透视脚本,手... 关于透视!德州真人透视脚本,手机微乐小程序游戏破解器,攻略教程(有挂工具)-哔哩哔哩;1、打开软件启...
透视教程!cloudpoker... 透视教程!cloudpoker作必弊,越乡游辅助工具,指引教程(证实有挂)-哔哩哔哩1、游戏颠覆性的...
最新技巧!!潮汕木虱有辅助挂吗... 最新技巧!!潮汕木虱有辅助挂吗,德州透视hhpoker,攻略教程(有挂方略)-哔哩哔哩潮汕木虱有辅助...
出乎意料的是!山西扣点点脚本辅... 出乎意料的是!山西扣点点脚本辅助器,财神十三张福袋多少钱,办法教程(有挂教程)-哔哩哔哩1)山西扣点...
揭幕透视!sohoo poke... 揭幕透视!sohoo poker辅助,微乐科技软件下载,阶段教程(真是有挂)-哔哩哔哩在进入soho...
透视线上!德州透视脚本,皮皮跑... 透视线上!德州透视脚本,皮皮跑子胡子,要领教程(有人有挂)-哔哩哔哩1、超多福利:超高返利,海量正版...
刚刚!激k辅助器是真的吗,九九... 刚刚!激k辅助器是真的吗,九九联盟辅助在,策略教程(有挂教学)-哔哩哔哩1、激k辅助器是真的吗破解器...
科技通报!哈灵脚本辅助最简单三... 科技通报!哈灵脚本辅助最简单三个步骤,wepoker数据分析,窍要教程(新版有挂)-哔哩哔哩1、哈灵...
总结透视!wepoker辅助器... 总结透视!wepoker辅助器,微信小程序微乐辅助器免费版,阶段教程(有挂教学)-哔哩哔哩亲,关键说...
昨日!pokerworld辅助... 昨日!pokerworld辅助器,雀姬胡牌辅助,练习教程(证实有挂)-哔哩哔哩在进入pokerwor...