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

相关内容

热门资讯

透视解密!hhpoker怎么防... 透视解密!hhpoker怎么防作必弊,hh poker软件(透视)都是真的有神器(哔哩哔哩)1、这是...
透视策略!菠萝辅助器免费版的功... 透视策略!菠萝辅助器免费版的功能介绍,HHpoker机器人好像真的是有工具,1分钟教程(了解有挂)1...
透视软件!德普之星辅助器app... 透视软件!德普之星辅助器app,微乐智能插件激活码,解迷脚本(有挂透明挂)-哔哩哔哩1、让任何用户在...
第5分钟项目!多乐跑得私人房间... 第5分钟项目!多乐跑得私人房间作必弊视频,新超凡大厅辅助(辅助)切实真的有app(哔哩哔哩)1、超多...
透视揭幕!德普之星辅助器,德扑... 透视揭幕!德普之星辅助器,德扑圈透视(透视)原来存在有方法(哔哩哔哩)在进入软件靠谱后,参与本局比赛...
透视阶段!WePoKer辅助器... 透视阶段!WePoKer辅助器,WePoKer挂一直有脚本,第5分钟教程(有挂攻略)1、WePoKe...
第9分钟资料!开心泉州小程序开... 第9分钟资料!开心泉州小程序开挂有什么技巧,财神十三张安装工具(辅助)确实真的有软件(哔哩哔哩)1、...
透视攻略!wepoker私人定... 透视攻略!wepoker私人定制透视,微信小程序微乐房间的挂多少钱,有挂透视(有挂实锤)-哔哩哔哩1...
脚本详细!wepoker辅助器... 脚本详细!wepoker辅助器激活码,wepoker模拟器哪个好用(透视)真是真的有教程(哔哩哔哩)...
透视步骤!aapoker脚本怎... 透视步骤!aapoker脚本怎么用,AApoker中牌率一直是有辅助,第6分钟教程(了解有挂)1、操...