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

相关内容

热门资讯

必备透视!pokemomo辅助... 必备透视!pokemomo辅助工具!玩家攻略推荐辅助教程(有挂透明挂)-哔哩哔哩1、下载好pokem...
透视真的!wpk俱乐部是真的吗... 透视真的!wpk俱乐部是真的吗(透视)一直真的是有辅助修改器(有挂秘籍)-哔哩哔哩1、透视真的!wp...
近日!仙神互娱辅助,九哥大厅辅... 近日!仙神互娱辅助,九哥大厅辅助,绝活教程(有挂讲解)-哔哩哔哩1、任何仙神互娱辅助透视是真的假的的...
必看攻略!wepoker手机插... 必看攻略!wepoker手机插件,宁波同乡游辅助下载,竟然有辅助神器(有挂详情)1)宁波同乡游辅助下...
分享透视!wepoker有插件... 分享透视!wepoker有插件吗!普及知识辅助神器(有挂细节)-哔哩哔哩1、打开软件启动之后找到中间...
据监测!佛手在线大菠萝辅助(透... 据监测!佛手在线大菠萝辅助(透视)其实是真的辅助下载(揭秘有挂)-哔哩哔哩1、起透看视 佛手在线大菠...
指导大家!pokermaste... 指导大家!pokermaster破解版,新道游科技透视通用版1,竟然存在有辅助教程(有挂解惑)1、下...
今天下午!新海贝之城拼十房间,... 今天下午!新海贝之城拼十房间,欢乐对决合作辅助,烘培教程(有挂工具)-哔哩哔哩1、操作简单,无需新海...
透视模拟器!aapoker透视... 透视模拟器!aapoker透视方法(透视)都是是真的辅助app(有人有挂)-哔哩哔哩1、aapoke...
解谜透视!aapoker破解侠... 您好,aapoker破解侠是真的吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【4852750...