当前位置: 代码迷 >> 综合 >> 导出excel 报错The maximum column width for an individual cell is 255 characters
  详细解决方案

导出excel 报错The maximum column width for an individual cell is 255 characters

热度:58   发布时间:2023-11-23 11:13:03.0

一、背景
导出excel,某列数据太长
二、解决

/*** 自动调整列宽** @param sheet* @param columnNumber*/private static void autoSizeColumns(Sheet sheet, int columnNumber) {for (int i = 0; i < columnNumber; i++) {int orgWidth = sheet.getColumnWidth(i);sheet.autoSizeColumn(i, true);int newWidth = (int) (sheet.getColumnWidth(i) + 100);int maxWith = 256*255;//限制下最大宽度if(newWidth > maxWith) {sheet.setColumnWidth(i, maxWith);}else if (newWidth > orgWidth) {sheet.setColumnWidth(i, newWidth);} else {sheet.setColumnWidth(i, orgWidth);}}}

宽度超过256*255就不要再往大设置了,使其自动折叠即可

  相关解决方案