The maximum number of cell styles was exceeded poi 超过 最大style 4000 解决方法

今天导出excel功能有个问题,我捕获了一下发现是 poi中 style超过4000个

Caused by: java.lang.IllegalStateException: The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook
 at org.apache.poi.hssf.usermodel.HSSFWorkbook.createCellStyle(HSSFWorkbook.java:1144)
 at org.apache.poi.hssf.usermodel.HSSFWorkbook.createCellStyle(HSSFWorkbook.java:88)
 at com.trendmicro.util.toExcel.ExcelExporter.addWorkbook(ExcelExporter.java:612)
 at com.trendmicro.util.toExcel.ExcelExporter.exportToExcel(ExcelExporter.java:112)
 at com.trendmicro.util.toExcel.ReportExporter.exportAutomationReport(ReportExporter.java:190)
 at com.trendmicro.view.reports.TestCaseAutomationBean.exportAutoReport(TestCaseAutomationBean.java:856)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.apache.el.parser.AstValue.invoke(AstValue.java:191)
 at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
 at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
 at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)

 

解决方法

把createStyle放到for循环外头 检查创建次数

 

你可能感兴趣的:(错误解决集锦)