`
zhouchaofei2010
  • 浏览: 1104130 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

The maximum number of cell styles was exceeded. You can define up to 4000 styles

 
阅读更多

转自 http://blog.sina.com.cn/s/blog_62e744e60100qjix.html

 

excel poi中,导出的数据不是很大时,则不会有问题,而数据很多或者比较多时,

就会报以下的错误,是由于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

-------------------示例---------------

Wrong :

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);

}
Correct:
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);

}
Note : LOC of creating fonts is inside the loop , because when you are writing the records to the row.  there is no need of keeping the font creation in loop , better move it outside the loop and try it . Sure popup message will not come in case of large datas populated in the worksheet .

分享到:
评论

相关推荐

    You can define up to 4000 styles in a .xls workbook is a wrong excepiton

    The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook is a wrong excepiton 将抛异常的方法去掉,是程序继续执行,生成excel 。本来想免费,但是苦于没积分所以...

    解决样式多问题 You can define up to 4000 styles 包括poi全部jar

    描述中的信息进一步解释了这个问题:“The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook”。这意味着当尝试创建更多的单元格样式时,系统会报错,因为`.xls`...

    解决PROTEL99SE经常弹出WARNING

    解决常见的破解不完全问题:The maximum number of licenses has been exceeded for the following servers 弹窗! 将此文件替换安装目录C:\Program Files\Design Explorer 99 SE,如当初安装protel99时自定义了安装...

    openssh升级文档(以ssh8.4为例)

    例如,您可能会遇到“Job for sshd.service failed because a timeout was exceeded”的错误。这通常是由于服务启动超时或者配置问题导致的。解决方法包括检查sshd的状态(`systemctl status sshd.service`)和日志...

    解决shader256关键字报错问题ShaderKeywordsTool.zip

    整个unity里面的shader的#pragma multi xxxxx_ON 关键字不能超过256个,给系统添加负担...所以会报错:maximum number (256) of shader keywords exceeded unity。 做法是减少关键字的使用。 下面提供一个优化工具。

    详解 Java Maximum redirects (100) exceeded

    "Java Maximum redirects (100) exceeded" Java Maximum redirects (100) exceeded是指在Java中使用HttpClient进行网络请求时,遇到的最大重定向次数限制问题。该问题的主要原因是HttpClient的默认设置中,最大...

    微软内部资料-SQL性能优化2

    The boot.ini option /3GB was created for those cases where systems actually support greater than 2 GB of physical memory and an application can make use of it This capability allows memory intensive ...

    Maximum file size of X KB exceeded(解决方案).md

    Maximum file size of X KB exceeded(解决方案).md

    EHLib 6.3.171〖D7~XE5〗

    This property can be assigned by a maximum time, which will be used to calculate the widths of the columns when the user double click on the line that separates columns. If the time of calculation ...

    BURNINTEST--硬件检测工具

    - Updated the detection of Hyperthreading and the number of logical CPUs for a new Intel CPU. Release 5.3 build 1025 WIN32 release 11 July 2008 - Corrected a Disk test bug where on rare occasions a...

    Maximum最大值

    在IT领域,尤其是在编程与数据处理中,“Maximum最大值”是一个极为重要的概念,它涉及到如何在一组数值或数据集合中找到最大的元素。这个概念在多种编程语言和算法中都有广泛的应用,例如在Java、Python、C++等语言...

    Bayesian Network(贝叶斯网络) Python Program

    code to perform actions whenever an output node's threshold is exceeded. It could include code to generate events (rather than read them from a file). And it could include code to describe more ...

    wp-o-matic.1.0RC4.zip

    The best way to organize your feeds is up to you. == Screenshots == 1. Dashboard 2. Campaigns list 3. Add campaign main tab 4. Add campaign feeds tab 5. Add campaign categories tab 6. Add campaign ...

    S7A驱动720版本

    - The own address of CIF50 MPI/PB communication way was limited to 31. Now the limit is 126. - Bug-fix in PG-PC Interface (CP5611) communication way. Device could be disabled from polling, after ...

    解决PHP程序运行时:Fatal error: Maximum execution time of 30 seconds exceeded in的错误提示

    最近做的程序中涉及到的循环比较多且处理的情况较复杂,在运行程序时出现执行超时提示如下:Fatal error: Maximum execution time of 30 seconds exceeded in D:phpAppServwwwsum3test.php on line 3通过在网上搜索...

    10个protel99se序列号

    ### Protel99se 序列号及其在局域网中的应用 #### 一、Protel99se简介 Protel99SE是一款由Altium公司开发的专业电路设计软件,广泛应用于电子工程领域,用于原理图绘制、PCB设计、信号完整性分析等方面。...

    大学英语四级翻译和语法.doc

    - When the menu was brought, I was shocked at the prices, which far exceeded my expectations. - Effective measures must be taken immediately to eliminate sandstorms. 4. 情态动词: - The phone is ...

    hive on spark mr 数据开发常见问题解决

    在Hive on Spark作业中,如果遇到`Failed to get a spark session`,可能是因为YARN资源在某些时段紧张。一种解决方法是增加Hiveserver2中的`hive.spark.client.server.connect.timeout`参数,将其设为更长的时间,...

    文件和进程隐藏与检测

    Initially the first article was an experiment and the result of it exceeded all my expectations. I want to thank all readers who left comments and wrote emails, your opinions were really important ...

Global site tag (gtag.js) - Google Analytics