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

相关内容

热门资讯

黑科技代打(wepoke智能a... 黑科技代打(wepoke智能ai)wepokeapp下载教程(wEpoke)一直有挂(真的有挂)-哔...
黑科技中牌率(wepoke真的... 黑科技中牌率(wepoke真的有挂)wepoke有辅助吗(Wepoke)从来是真的有挂(有挂技术)-...
黑科技教学(wepoke黑科技... 这是一款非常优秀的 ia辅助检测软件,能够让你了解到中牌率当中全部隐藏参数,与同类被系统制裁软件相比...
黑科技智能ai(wepoke透... 黑科技智能ai(wepoke透明黑科技)wopoker轻量版外挂(wePOke)原本是有挂(有挂讲解...
黑科技玄学(wepoke辅助插... 黑科技玄学(wepoke辅助插件)wepoke软件透明(WEPOke)本然存在有挂(真的有挂)-哔哩...
黑科技脚本(wepoke黑科技... 黑科技脚本(wepoke黑科技)We辅poker助(wePoKe)原生有挂(了解有挂)-哔哩哔哩;揭...
黑科技了解(wepoke黑科技... 《软件透明挂》是一款多人竞技的辅助透视游戏,你将微扑克对手来到同一个战场,为至高无上的荣耀进行一次自...
黑科技辅助(wepoke透明黑... 黑科技辅助(wepoke透明黑科技)wopoker系统机制(wepoker)果然是有挂(有挂存在)-...
黑科技安卓版(wepoke智能... 黑科技安卓版(wepoke智能ai)Wepoke黑科技设备(wepoker)都是有挂(有挂解惑)-哔...
黑科技辅助挂(wepoke透明... 黑科技辅助挂(wepoke透明黑科技)wpeoke软件下载(WEpoke)竟然存在有挂(竟然有挂)-...