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

导出excel报错。错误日志提示::The maximum length of cell contents (text) is 32767 characters
在这里插入图片描述

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

解决方案:

  • 通过java反射机制,设置单元格最大校验限制为Integer.MAX_VALUE(2147483647)。
  • 导出生成excel文件之前调用下边设置单元格最大限制方法。
	/** 
	  * @Description: 利用反射强制将EXCEL2007中的_maxTextLength属性值修改为Integer.MAX_VALUE
	  * @author: ly
	  * @date: 2024/2/6 
	  **/
	public static 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();
			}
		}
	}
  • 使用
ExcelUtils.resetCellMaxTextLength();
ResponseUtils.writeExcel(response, workbook, "反馈结果统计信息.xlsx");

相关推荐

  1. excel导入导出

    2024-02-07 15:30:02       19 阅读
  2. Excel 导入导出的封装

    2024-02-07 15:30:02       20 阅读
  3. 用于Web导出excel

    2024-02-07 15:30:02       29 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-02-07 15:30:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-07 15:30:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-07 15:30:02       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-07 15:30:02       20 阅读

热门阅读

  1. WebSocketServer依赖注入问题

    2024-02-07 15:30:02       29 阅读
  2. Android设置默认8时区和默认24小时制

    2024-02-07 15:30:02       33 阅读
  3. 【seata自动化治愈数据库问题解决方案】

    2024-02-07 15:30:02       36 阅读
  4. λ-矩阵知识点

    2024-02-07 15:30:02       53 阅读
  5. rancher迁移账号密码

    2024-02-07 15:30:02       34 阅读
  6. spring 熔断机制

    2024-02-07 15:30:02       31 阅读
  7. 自定义指令实现图片懒加载

    2024-02-07 15:30:02       33 阅读
  8. CentOS 7 安装 install abiword

    2024-02-07 15:30:02       32 阅读