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

相关内容

热门资讯

揭幕透视!pokemmo内置修... 揭幕透视!pokemmo内置修改器,大菠萝免费辅助(透视)其实是有辅助技巧(哔哩哔哩)1、完成pok...
第三方技巧!哈糖大菠萝免费辅助... 第三方技巧!哈糖大菠萝免费辅助器,新西部大厅辅助器,诀窍辅助软件(有挂教程)-哔哩哔哩哈糖大菠萝免费...
专业透视!pokermaste... 专业透视!pokermaster破解版,悦扑克脚本(透视)一直一直都是有辅助教程(哔哩哔哩)1、游戏...
这一现象值得深思!佛手在线大菠... 这一现象值得深思!佛手在线大菠萝智能辅助器,拱趴大菠萝辅助,项目辅助技巧(有挂解密)-哔哩哔哩在进入...
教你透视!pokemmo手机脚... 教你透视!pokemmo手机脚本,拱趴大菠萝机器人(透视)切实是真的有辅助插件(哔哩哔哩)拱趴大菠萝...
黑科技辅助挂!newpoker... 黑科技辅助挂!newpoker脚本,天天透视辅助工具,指引辅助插件(有挂方式)-哔哩哔哩1、玩家可以...
普及透视!pokemmo辅助脚... 普及透视!pokemmo辅助脚本,竞技联盟破解版最新版(透视)果然一直总是有辅助脚本(哔哩哔哩)1....
明白辅助挂!智星德州插件,新蛮... 明白辅助挂!智星德州插件,新蛮王辅助器,指南书辅助脚本(竟然有挂)-哔哩哔哩1、起透看视 智星德州插...
辅助透视!德州透视是真的假的,... 辅助透视!德州透视是真的假的,菠萝辅助器免费版的功能介绍(透视)果然是真的有辅助方法(哔哩哔哩)1、...
开挂透视!pokerworld... 开挂透视!pokerworld辅助器,pokemmo免费脚本(透视)一贯是有辅助脚本(哔哩哔哩)1、...