EasyExcel导出时提示“单元格存储内容超过了最大 32767 个字符”的解决方法


解决用EasyExcel导出文件时,提示“The maximum length of cell contents (text) is 32,767 characters”的方法。

问题

解决

利用反射强制将EXCEL2007中的_maxTextLength属性值修改为Integer.MAX_VALUE
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();
        }
    }
}

使用

在EasyExcel调用之前执行即可
ExcelTool.resetCellMaxTextLength();
EasyExcel.write(getAbsoluteFile(filename), clazz).sheet(sheetName).doWrite(list);

声明:目的地-Destination|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - EasyExcel导出时提示“单元格存储内容超过了最大 32767 个字符”的解决方法


前程似锦、未来可期、寻得良人、共赴白头,祝你也祝我。