一、问题描述

在导出一些数据抛:

java.lang.IllegalArgumentException: The maximum length of cell contents (text) is 32767 characters

at org.apache.poi.ss.usermodel.CellBase.checkLength(CellBase.java:309)

at org.apache.poi.ss.usermodel.CellBase.setCellValue(CellBase.java:290)

二、产生原因

根据日志异常栈提示:at org.apache.poi.ss.usermodel.CellBase.checkLength(CellBase.java:309)

定位到 CellBase 类 checkLength 方法 309 行

private void checkLength(String value) {// value值超过了 32767if(value.length() > getSpreadsheetVersion().getMaxTextLength()){final String message = String.format(Locale.ROOT,"The maximum length of cell contents (text) is %d characters",getSpreadsheetVersion().getMaxTextLength());throw new IllegalArgumentException(message);}
}

getSpreadsheetVersion().getMaxTextLength()  枚举源码类

public enum SpreadsheetVersion {/*** Excel97 format aka BIFF8* <ul>* <li>The total number of available rows is 64k (2^16)</li>* <li>The total number of available columns is 256 (2^8)</li>* <li>The maximum number of arguments to a function is 30</li>* <li>Number of conditional format conditions on a cell is 3</li>* <li>Number of cell styles is 4000</li>* <li>Length of text cell contents is 32767</li>* </ul>*/EXCEL97(0x10000, 0x0100, 30, 3, 4000, 32767),/*** Excel2007** <ul>* <li>The total number of available rows is 1M (2^20)</li>* <li>The total number of available columns is 16K (2^14)</li>* <li>The maximum number of arguments to a function is 255</li>* <li>Number of conditional format conditions on a cell is unlimited* (actually limited by available memory in Excel)</li>* <li>Number of cell styles is 64000</li>* <li>Length of text cell contents is 32767</li>* <ul>*/EXCEL2007(0x100000, 0x4000, 255, Integer.MAX_VALUE, 64000, 32767);private final int _maxRows;private final int _maxColumns;private final int _maxFunctionArgs;private final int _maxCondFormats;private final int _maxCellStyles;private final int _maxTextLength;private SpreadsheetVersion(int maxRows, int maxColumns, int maxFunctionArgs, int maxCondFormats, int maxCellStyles, int maxText) {_maxRows = maxRows;_maxColumns = maxColumns;_maxFunctionArgs = maxFunctionArgs;_maxCondFormats = maxCondFormats;_maxCellStyles = maxCellStyles;_maxTextLength = maxText;}/*** @return the maximum number of usable rows in each spreadsheet*/public int getMaxRows() {return _maxRows;}/*** @return the last (maximum) valid row index, equals to <code> getMaxRows() - 1 </code>*/public int getLastRowIndex() {return _maxRows - 1;}/*** @return the maximum number of usable columns in each spreadsheet*/public int getMaxColumns() {return _maxColumns;}/*** @return the last (maximum) valid column index, equals to <code> getMaxColumns() - 1 </code>*/public int getLastColumnIndex() {return _maxColumns - 1;}/*** @return the maximum number arguments that can be passed to a multi-arg function (e.g. COUNTIF)*/public int getMaxFunctionArgs() {return _maxFunctionArgs;}/*** @return the maximum number of conditional format conditions on a cell*/public int getMaxConditionalFormats() {return _maxCondFormats;}/*** @return the maximum number of cell styles per spreadsheet*/public int getMaxCellStyles() {return _maxCellStyles;}/**** @return the last valid column index in a ALPHA-26 representation*  (<code>IV</code> or <code>XFD</code>).*/public String getLastColumnName() {return CellReference.convertNumToColString(getLastColumnIndex());}/*** @return the maximum length of a text cell*/public int getMaxTextLength() {return _maxTextLength;}
}

三、解决方案

通过,反射去修改 SpreadsheetVersion 的 _maxTextLength 变量即可。

( 注:这里仅仅只是为了突破cell的内容限制而作修改,理论上,修改 final 变量肯定是不合理的 )

/*** 初始化 cell 内容长度*     cell 原本内容长度限制 32767  现修改为Integer.MAX_VALUE
*/
public static void initCellMaxTextLength() {SpreadsheetVersion excel2007 = SpreadsheetVersion.EXCEL2007;if (Integer.MAX_VALUE != excel2007.getMaxTextLength()) {Field field;try {field = excel2007.getClass().getDeclaredField("_maxTextLength");field.setAccessible(true);field.set(excel2007,Integer.MAX_VALUE);} catch (Exception e) {e.printStackTrace();}}}// 导出数据前调用
initCellMaxTextLength();

1、cell 内容最大长度 The maximum length of cell contents (text) is 32767 characters相关推荐

  1. java.lang.IllegalArgumentException: The maximum length of cell contents (text) is 32,767 characters

    问题描述: 在使用EasyExcel导出Excel的过程中出现了如下异常: IllegalArgumentException: The maximum length of cell contents ...

  2. leetcode 1239. Maximum Length of a Concatenated String with Unique Characters | 1239. 串联字符串的最大长度(回溯)

    题目 https://leetcode.com/problems/contiguous-array/ 题解 回溯法,每个字符串都有可能加或者不加. class Solution {int N;publ ...

  3. oracle sqlldr 数据导入时报错:Field in data file exceeds maximum length

    使用oracle sqlldr进行数据导入时报Field in data file exceeds maximum length错误: 在ctl文件中设置的数据长度小于实际数据长度 如: column ...

  4. 求两个数组的最长重复子数组 Maximum Length of Repeated Subarray

    为什么80%的码农都做不了架构师?>>>    问题: Given two integer arrays A and B, return the maximum length of ...

  5. 限制Textarea文本域内容的长度

    通过charCodeAt()函数获取字符的Unicode值,根据Unicode值得范围判断字符串中是否包含中文符,包含temp+2,不包含temp+1: 在body标签的onload加载事件中调用Ja ...

  6. arry-718 Maximum Length of Repeated Subarray

    题目:Input: A: [1,2,3,2,1] B: [3,2,1,4,7] Output: 3 Explanation: The repeated subarray with maximum le ...

  7. Maximum length exceeded错误的解决办法

    一.问题 在序列化或反序列化对象时,由于对象数据量过大,超出了默认长度,引起程序抛出"maximum length exceeded"异常. 二.解决 在Web.config的&l ...

  8. oracle sqlldr 数据导入错误Field in data file exceeds maximum length解决

    使用oracle sqlldr进行数据导入时报Field in data file exceeds maximum length错误的解决办法: 一种是数据字段确实比数据库中的字段要长,这中错误需要调 ...

  9. oracle+exceeds,oracle 导入报错:field in data file exceeds maximum length

    今天用sqlldr导入数据时候报错: " Record 1: Rejected - Error on table ks_test, column khname. Field in data ...

  10. oracle sqlldr 数据导入时报错:Field in data file exceeds maximum length完美解决

    使用oracle sqlldr进行数据导入时报Field in data file exceeds maximum length错误的解决办法: 一种是数据字段确实比数据库中的字段要长,这中错误需要调 ...

最新文章

  1. 就《在企业中发起和推广DevOps》的问答
  2. java securt 视频,SecureRandom在Java中安全种子
  3. swift-UITextfield控件的基本属性设置
  4. 音视频开发(19)---Android视频开发基础(一)
  5. html5 websocket插件,html5实现的WebSocket一个小例子(附代码)
  6. Sybase 事务和嵌套事务
  7. android获取wifi mac地址吗,Android获取当前WiFi的MAC地址-适配所有版本
  8. 使用CrossFTP跨越不同站点复制/移动数据
  9. 去掉超链接或图片热点链接虚线框
  10. Spring Security基本原理
  11. 【离散数学】图论 第七章(3) 图的矩阵表示(邻接矩阵、可达矩阵、传递闭包求解算法)
  12. 欢迎访问我的个人主页 Welcome to my home
  13. 关于快速幂与快速积取模实现的尝试
  14. 设计篇-网页设计规范
  15. 央视财经采访:康晓阳投资分享
  16. 腾讯2021校园招聘-后台综合-第一次笔试 8.23 20.00-22.00 Apare_xzc
  17. 使用两个FBO互相绑定实现PS液化效果
  18. flutter编译遇到unknown revision or path not in the working tree的错误
  19. zcmu 1919: kirito's 星爆气流斩
  20. Oracle分区简介

热门文章

  1. mysql error1205 博客_Mysql Error:1205错误诊断
  2. centos-ssh-channel is not opened.
  3. Java设计模式学习笔记
  4. 基于redis幂等机制,保证优惠券不会重复发放-13
  5. 异常:The JSP specification requires that an attribute name is preceded by whitespace
  6. esxi 快照整合_ESXi删除最后的快照
  7. chrome常用扩展程序汇总(程序员版)
  8. MySQL数据库进阶知识
  9. remix下ballot.sol调试
  10. 金融级湖仓一体架构——SequoiaDB巨杉数据库初探