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

相关内容

热门资讯

第4分钟辅助!微信小程序免费黑... 第4分钟辅助!微信小程序免费黑科技,微乐麻将脚本透视(一直真的是有外挂软件)-哔哩哔哩1、下载好微信...
透视手段!wepoker透视底... 透视手段!wepoker透视底牌脚本,wepoker辅助软件价格(透视)确实真的有脚本脚本(哔哩哔哩...
8分钟安装!微乐自建房插件如何... 8分钟安装!微乐自建房插件如何安装,微乐自建房辅助工具免费(果然是真的外挂脚本)-哔哩哔哩1)微乐自...
透视指引!aapoker发牌逻... 透视指引!aapoker发牌逻辑,aapoker辅助器怎么用(透视)确实是真的透视插件(哔哩哔哩)1...
透视窍门!wpk是真的还是假的... 透视窍门!wpk是真的还是假的,wepoker破解器(透视)好像真的是有挂(哔哩哔哩)wpk是真的还...
第2分钟插件!微乐小程序自建房... 第2分钟插件!微乐小程序自建房透视下载,微乐锄大地脚本(一贯是真的外挂辅助器)-哔哩哔哩1、进入到微...
透视办法!wpk模拟器多开,w... 透视办法!wpk模拟器多开,wpk辅助(透视)竟然是有脚本app(哔哩哔哩)1、完成wpk模拟器多开...
透视练习!wepoker有插件... 透视练习!wepoker有插件吗,wpk德州局透视(透视)原来真的有挂(哔哩哔哩)1、打开软件启动之...
7分钟脚本!微信小程序免费黑科... 7分钟脚本!微信小程序免费黑科技,微信微乐陕西小程序辅助器(确实真的有外挂下载)-哔哩哔哩1、任何微...
透视指引!wepoker一直输... 透视指引!wepoker一直输的号能继续打吗,wepoker私人局辅助挂(透视)好像真的有挂(哔哩哔...