首页 > 数据库 >excel 导出 The maximum length of cell contents (text) is 32767 characters Excel单元格最大存储长度32767个字符,超长会报

excel 导出 The maximum length of cell contents (text) is 32767 characters Excel单元格最大存储长度32767个字符,超长会报

时间:2023-10-12 09:45:38浏览次数:46  
标签:return int excel 32767 报错 ._ 长度 public

excel 导出 The maximum length of cell contents (text) is 32767 characters

导出excel功能,报错。错误日志提示::The maximum length of cell contents (text) is 32767 characters

调查后,poi会有单元格最大长度校验超过32767会报错。

需求调研:
调研发现,excel和csv文件本身存在单元格有32767的最大字符限制。

解决方案:
解决办法是程序不报错,但是生成excel或者csv 会自动截取单元格最大32767 characters。

1、通过java反射机制,设置单元格最大校验限制为Integer.MAX_VALUE(2147483647)。
导出生成excel文件之前调用设置单元格最大限制方法。

public void resetCellMaxTextLength() {
        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();
            }
        }
    }

2、修改源码,修改源码文件枚举类,同样也是设置最大校验限制为Integer.MAX_VALUE

package org.apache.poi.ss;
import org.apache.poi.ss.util.CellReference;
/**
 * @description :Excel枚举
 */
public enum SpreadsheetVersion {
    /**
     * excel 枚举
     **/
    EXCEL97(65536, 256, 30, 3, 4000, 32767),
    EXCEL2007(1048576, 16384, 255, 2147483647, 64000, Integer.MAX_VALUE);
    private final int _maxRows;
    private final int _maxColumns;
    private final int _maxFunctionArgs;
    private final int _maxCondFormats;
    private final int _maxCellStyles;
    private final int _maxTextLength;
<span class="hljs-keyword">private</span> SpreadsheetVersion(int maxRows, int maxColumns, int maxFunctionArgs, int maxCondFormats, int maxCellStyles, int maxText) {
    <span class="hljs-keyword">this</span>._maxRows = maxRows;
    <span class="hljs-keyword">this</span>._maxColumns = maxColumns;
    <span class="hljs-keyword">this</span>._maxFunctionArgs = maxFunctionArgs;
    <span class="hljs-keyword">this</span>._maxCondFormats = maxCondFormats;
    <span class="hljs-keyword">this</span>._maxCellStyles = maxCellStyles;
    <span class="hljs-keyword">this</span>._maxTextLength = maxText;
}

<span class="hljs-keyword">public</span> int getMaxRows() {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>._maxRows;
}

<span class="hljs-keyword">public</span> int getLastRowIndex() {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>._maxRows - <span class="hljs-number">1</span>;
}

<span class="hljs-keyword">public</span> int getMaxColumns() {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>._maxColumns;
}

<span class="hljs-keyword">public</span> int getLastColumnIndex() {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>._maxColumns - <span class="hljs-number">1</span>;
}

<span class="hljs-keyword">public</span> int getMaxFunctionArgs() {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>._maxFunctionArgs;
}

<span class="hljs-keyword">public</span> int getMaxConditionalFormats() {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>._maxCondFormats;
}

<span class="hljs-keyword">public</span> int getMaxCellStyles() {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>._maxCellStyles;
}

<span class="hljs-keyword">public</span> String getLastColumnName() {
    <span class="hljs-keyword">return</span> CellReference.convertNumToColString(<span class="hljs-keyword">this</span>.getLastColumnIndex());
}

<span class="hljs-keyword">public</span> int getMaxTextLength() {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>._maxTextLength;
}

}


32767 是 2的15次方减1. 即可容纳不超过2的15次方的字符. 但请注意在单元格中只可显示1024个字符. 可在编辑栏中显示全部的32767个字符.
以前2003每个单元格只可容纳255个字符. 即256-1个. 此后版本的excel做了改进. 才能容纳更多的字符.

原文链接:https://www.cnblogs.com/stubborn-dude/p/17552839.html

标签:return,int,excel,32767,报错,._,长度,public
From: https://www.cnblogs.com/sunny3158/p/17758747.html

相关文章

  • 如何解决小程序打开授权报错openSetting:fail can only be invoked by user TAP gestu
    要解决这个问题,你需要在页面上为openSetting接口添加一个点击事件。根据微信小程序的文档,openSetting接口只能通过用户点击行为(如tap事件)来触发。以下是一个简单的示例代码:<!--index.wxml--><view><buttonbindtap="openSetting">打开授权设置</button></view......
  • MySQL连接数超出最大值报错及修改
    报错:createconnectionSQLException,url:jdbc:mysql://xx.xxx.x.xx:6306/hksk-cloud-mes?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai,errorCode1040,s......
  • @Test下jedisManager.getJedis报错NullPointerException
    原文链接:https://www.longkui.site/error/test%e4%b8%8bjedismanager-getjedis%e6%8a%a5%e9%94%99nullpointerexception/4813/报错代码:importorg.junit.Test;importredis.clients.jedis.Jedis;@AutowiredprivateJedisManagerjedisManager;publicclassTestDem......
  • c++编译报错解决办法
    所有的警告都被当作是错误在全局域:cc1plus:错误:unrecognizedcommandlineoption‘-Wno-unknown-warning’[-Werror]cc1plus:所有的警告都被当作是错误解决办法:去除CMakeLists.txt中的-Werror......
  • 问题记录贴:vue-i18n在弹出框中$t()报错:TypeError: Cannot read property '_t' of unde
    网上有用的解决方法:vue国际化在弹出框中$t()报错:TypeError:Cannotreadproperty'_t'ofundefined大佬给出的解决方法:弹窗是一个新的Vue对象,只需要单独给弹窗重新绑定i18n即可。代码://dialog/main.jsimportcustomDialogfrom'./dialog.vue'importi18nfrom'@/i18n'......
  • python报错cannot import name ‘compare_ssim‘ from ‘skimage.measure‘
    问题原因: scikit-image版本过高导致 解决办法: 重装,安装低版本 pipuninstallscikit-imagepipinstallscikit-image==0.15.0-U-ihttps://pypi.tuna.tsinghua.edu.cn/simple ......
  • vue3+vite import 引入ThreeBSP库 报错
    我在网上查了一下先用npm下载了三方包npmithree-js-csg再使用constThreeBSP=require('three-js-csg')(THREE)的方法引入出现了这个报错查了是因为require是webpack里的vite不支持所以找不到然后我就尝试使用import的方法引入importThreeBSPfrom'three-js......
  • 报错Intel MKL FATAL ERROR: Cannot load libmkl_core.so.的一种解决方法
    问题今天上80服务器跑mdistiller的代码时,意外发现torch、numpy都不能用了T_T以torch为例,出现如下报错情况以numpy为例,出现如下报错情况我们先看看报错信息,这个报错来自InterMKL。InterMKL全称是TheIntelMathKernelLibrary,它是一个主要是用于科学计算的共享库,提供了很......
  • 执行wordcount报错及解决
    今天在执行wordcount词频统计时报错执行语句为hadoopjarshare/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.3.jarwordcountwcinputwcoutput报错如下 这表示指定的输入路径hdfs://hadoop102:8020/user/atguigu/wcinput不存在然后我打开hadoop可视化网页一看确实......
  • powercli报错问题的解决
    报错如图PSC:\Users\admin>Connect-VIServer-Server160.x.x.10-Protocolhttps_userbu\rjkConnect-VIServer:The'Connect-VIServer'commandwasfoundinthemodule'VMware.VimAutomatcouldnotbeloaded.Formoreinformation,run&#......