java.lang.IllegalArgumentException: The maximum column width for an individual cell is 255 characters. org.apache.poi.xssf.usermodel.XSSFSheet.setColumnWidth(XSSFSheet.java:2386) com.lemon.web.XExcelServlet.attach(XExcelServlet.java:69) com.lemon.web.XExcelServlet.writeExcel(XExcelServlet.java:171) com.lemon.web.XExcelServlet.doGet(XExcelServlet.java:149) javax.servlet.http.HttpServlet.service(HttpServlet.java:617) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:404) org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:136) javax.servlet.http.HttpServlet.service(HttpServlet.java:617)javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
原因:导出excel时,excel表中的某个单元格数据过大,然而在创建时,使用了localHSSFSheet.setColumnWidth()控制住了单元格的列宽,所以会显示单元格最大列宽255错误。
解决办法:
1、将这段语句注释掉即可,单元格显示不美观(用的是poi-ooxml-3.14.jar)。
2、还有一种网上找到的方法:部分转自 https://www.cnblogs.com/frank-quan/p/7387936.html
for (int i = 0; i < headerList.size(); i++) { int colWidth = sheet.getColumnWidth(i)*2; if(colWidth<255*256){ sheet.setColumnWidth(i, colWidth < 3000 ? 3000 : colWidth); }else{ sheet.setColumnWidth(i,6000 ); } }
导出excel时报The maximum column width for an individual cell is 255 characters错误,原因及解决办法
最新推荐文章于 2024-12-05 09:54:26 发布