博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【转】The maximum number of cell styles was exceeded. You can define up to 4000 styles
阅读量:6403 次
发布时间:2019-06-23

本文共 2118 字,大约阅读时间需要 7 分钟。

POI操作Excel中,导出的数据不是很大时,则不会有问题,而数据很多或者比较多时,

就会报以下的错误,是由于cell styles太多create造成,故一般可以把cellstyle设置放到循环外面

报错如下:

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)
... 33 more

 

 

-------------实例----------------

错误代码:

for (int i = 0; i < 10000; i++) {      Row row = sheet.createRow(i);       Cell cell = row.createCell((short) 0);       CellStyle style = workbook.createCellStyle();      Font font = workbook.createFont();       font.setBoldweight(Font.BOLDWEIGHT_BOLD);       style.setFont(font);       cell.setCellStyle(style);  }

修改后代码:

CellStyle style = workbook.createCellStyle();  Font font = workbook.createFont();  font.setBoldweight(Font.BOLDWEIGHT_BOLD);  style.setFont(font);  for (int i = 0; i < 10000; i++) {       Row row = sheet.createRow(i);       Cell cell = row.createCell((short) 0);       cell.setCellStyle(style);  }

 

转载于:https://www.cnblogs.com/againn/p/9040816.html

你可能感兴趣的文章
2017年云计算成本将会更低
查看>>
Libratus – The AI that Defeated Humans in the Game of Poker
查看>>
WP ApplicationBar
查看>>
总结程序设计几大原则
查看>>
业界三种架构优缺点比较
查看>>
js报错:Ajax 中onreadystatechange在ie7及以上浏览器兼容吗,为什么没有反应?求大神...
查看>>
STL容器
查看>>
[Toolkit]Silverlight Toolkit 2009年10月 Release
查看>>
[WPF]WPF4.0中的字体呈现改进
查看>>
nginx-通过Nginx统计当前每个域名流量
查看>>
php中钩子(hook)的应用示例演示与下载
查看>>
pomelo--a安装时候错误总结
查看>>
二叉树与其它树
查看>>
H3 BPM前后台交互方法介绍
查看>>
Hyperledger Fabric Read-Write set semantics——读写集
查看>>
angular项目整合到.net mvc中
查看>>
Project network redundant , Vmware virtualization, Dell VRTX P2V - Part 3 (VRTX Installation)
查看>>
WSFC RODC部署模型
查看>>
(五)Docker镜像管理3之上传镜像
查看>>
elasticsearch 多次聚合
查看>>