poi导出excel报The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xl

poi导出excel报错:

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:1158)
 at org.apache.poi.hssf.usermodel.HSSFWorkbook.createCellStyle(HSSFWorkbook.java:76)
 at core.tools.opration.xls.XlsManager.export(XlsManager.java:107)
 at core.tools.opration.xls.XlsManager.export(XlsManager.java:40)
 at creditcc.server.controller.CallSummaryServlet.doPost(CallSummaryServlet.java:132)
 at creditcc.server.controller.CallSummaryServlet.doGet(CallSummaryServlet.java:55)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
 at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
 at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
 at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
 at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
 at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
 at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
 at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
 at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
 at org.mortbay.jetty.Server.handle(Server.java:324)
 at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
 at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)
 at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
 at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
 at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
 at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
 at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)

原因:是由于cell styles太多create造成

解决方法:修改poi源码中poi-3.8\src\java\org\apache\poi\hssf\usermodel\HSSFWorkBook.java中的一个参数(MAX_STYLES)的值,将其改大。

                   然后编译HSSFWorkBook.java.把编译好的HSSFWorkBook.class替换掉poi-3.8.jar中相应的.class文件

你可能感兴趣的:(java开发)