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

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

错误示例

改正后正确代码

  1. CellStyle style = workbook.createCellStyle();
  2. Font font = workbook.createFont();
  3. font.setBoldweight(Font.BOLDWEIGHT_BOLD);
  4. style.setFont(font);
  5. for (int i = 0; i < 10000; i++) {
  6. Row row = sheet.createRow(i);
  7. Cell cell = row.createCell((short) 0);
  8. cell.setCellStyle(style);
  9. }

以上方法原地址:http://blog.csdn.net/hoking_in/article/details/7919530

方法二(不推荐,影响性能):

1.4000最大样式错误

java.lang.IllegalStateException: The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook错误

找到zpoi.jar中org.zkoss.poi.hssf.usermodel.HSSFWorkbook修改createCellStyle函数内的最大样式数量即可。重新打zpoi.jar即可。

  1. public HSSFCellStyle createCellStyle()
  2. {
  3. if(workbook.getNumExFormats() == MAX_STYLES) {
  4. throw new IllegalStateException("The maximum number of cell styles was exceeded. " +
  5. "You can define up to 4000 styles in a .xls workbook");
  6. }
  7. ExtendedFormatRecord xfr = workbook.createCellXF();
  8. short index = (short) (getNumCellStyles() - 1);
  9. HSSFCellStyle style = new HSSFCellStyle(index, xfr, this);
  10. workbook.createCellXFExt(index);
  11. return style;
  12. }

IE兼容问题

如果IE系列的浏览器出现了兼容问题(具体就是显示不出报表来),我已知的可能出现的问题有,Excel模板里有数字已字符串形式写入,或者是写日期格式的单元格出现了写入错误。具体的解决如下。

数字形式写入代码

  1. public static Cell writeNumericValue(Sheet sheet, int row, int column,
  2. Double value) {
  3. Row poiRow = sheet.getRow(row);
  4. if (poiRow == null) {
  5. poiRow = sheet.createRow(row);
  6. }
  7. Cell poiCell = poiRow.getCell(column);
  8. if (poiCell != null) {
  9. poiRow.removeCell(poiCell);
  10. }
  11. poiCell = poiRow.createCell(column);
  12. poiCell.setCellType(Cell.CELL_TYPE_NUMERIC);
  13. poiCell.setCellValue(value);
  14. return poiCell;
  15. }

写入日期代码

  1. public static Cell writeDateValue(Workbook book, Sheet sheet, int row,
  2. int column, Date value) {
  3. Row poiRow = sheet.getRow(row);
  4. CreationHelper createHelper = book.getCreationHelper();
  5. if (poiRow == null) {
  6. poiRow = sheet.createRow(row);
  7. }
  8. Cell poiCell = poiRow.getCell(column);
  9. if (poiCell == null) {
  10. poiCell = poiRow.createCell(column);
  11. }
  12. CellStyle cellStyle = book.createCellStyle();
  13. cellStyle.setDataFormat(createHelper.createDataFormat().getFormat(
  14. "yyyy-mm-dd"));
  15. if (value != null) {
  16. poiCell.setCellValue(value);
  17. } else {
  18. poiCell.setCellValue(new Date());
  19. }
  20. poiCell.setCellStyle(cellStyle);
  21. return poiCell;
  22. }

以上方法原地址:http://realgodo.iteye.com/blog/1105529

The maximum number of cell styles was exceeded. You can define up to 4000 styles的更多相关文章

  1. 【POI】导出xls文件报错:The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook

    使用POI导出xls文件,由于数据过多,导致导出xls报错如下: The maximum number of cell styles was exceeded. You can define up t ...

  2. Failed to connect to database. Maximum number of conections to instance exceeded

    我们大体都知道ArcSDE的连接数有 48 的限制,很多人也知道这个参数可以修改,并且每种操作系统能支持的最大连接数是不同的. 如果应用报错:超出系统最大连接数 该如何处理? 两种解决办法: 第一,首 ...

  3. Exceeded maximum number of retries. Exceeded max scheduling attempts 3 for instance

    Exceeded maximum number of retries. Exceeded max scheduling attempts 3 for instance

  4. Exceeded maximum number of retries. Exceeded max scheduling attempts 3 for instance 7d90eb80-29e2-4238-b658-ade407ff9456. Last exception: [u'Traceback (most recent call last):\n', u' File "/usr/lib/py

    Exceeded maximum number of retries. Exceeded max scheduling attempts 3 for instance 7d90eb80-29e2-42 ...

  5. openstack-HTTP exception thrown: Maximum number of ports exceeded错误解决方案

    最近几天什么都没动无法创建云主机了,经过一番查询 1.查日志 /data/jumpserver/logs 得到错误 HTTP exception thrown: Maximum number of p ...

  6. Error: 实例 "ddd" 执行所请求操作失败,实例处于错误状态。: 请稍后再试 [错误: Exceeded maximum number of retries. Exhausted all hosts available for retrying build failures for instance 6f60bc06-fcb6-4758-a46f-22120ca35a71.].

    Error: 实例 "ddd" 执行所请求操作失败,实例处于错误状态.: 请稍后再试 [错误: Exceeded maximum number of retries. Exhaus ...

  7. "Your computer could not be joined to the domain. You have exceeded the maximum number of computer accounts you are allowed to create in this domain. Contact your system administrator to have this limit reset or increased."

    用一个普通的域帐号玩私有云的时候,遇到了如下的报错. "Your computer could not be joined to the domain. You have exceeded ...

  8. 错误: 实例 "ahwater-linux-core" 执行所请求操作失败,实例处于错误状态。: 请稍后再试 [错误: Exceeded maximum number of retries. Exceeded max scheduling attempts 3 for instance 7c1609c9-9d0f-4836-85b3-cefd45f942a7. Last exception: [u

    错误: 实例 "ahwater-linux-core" 执行所请求操作失败,实例处于错误状态.: 请稍后再试 [错误: Exceeded maximum number of ret ...

  9. ORA-00019: maximum number of session licenses exceeded 超出最大会话许可数

    ORA-00019: maximum number of session licenses exceededORA-00019: 超出最大会话许可数 Cause:       All licenses ...

随机推荐

  1. 摄像头(1)拍照的主要API,权限和特性,判断有没有摄像头的方法

    支持 Android SDK支持操作Android设备内置的照相机.从Android2.3开始,支持操作多个摄像头(主要指前置摄像头和后置照相机).通过照相机可以拍照和录像. 注意事项 是否支持照相机 ...

  2. WINCE6.0 error C2220: warning treated as error问题解决

    今天在编译IMX515的BSP的时候,发现下面的编译错误问题: BUILD: [00:0000002476:PROGC ] BuildingCOMPILE Pass in F:\WINCE600\PL ...

  3. Red hat Linux(Centos 5/6)安装R语言

    Red hat Linux(Centos 5/6)安装R语言1 wget http://cran.rstudio.com/src/base/R-3/R-3.0.2.tar.gz2 tar xzvf R ...

  4. hdu 1874 畅通工程续(模板题 spfa floyd)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1874 spfa 模板 #include<iostream> #include<stdio ...

  5. bzoj1937

    这道题没弄明白 初始模型很好想,是用到了最小生成树的性质 加入非树边后树上形成的环,非树边一定大于等于任意树边 然后考虑树边一定是缩小,非树边一定是增大 有di+wi>=dj-wj wi+wj& ...

  6. spring+springMVC+JPA配置详解(使用缓存框架ehcache)

    SpringMVC是越来越火,自己也弄一个Spring+SpringMVC+JPA的简单框架. 1.搭建环境. 1)下载Spring3.1.2的发布包:Hibernate4.1.7的发布包(没有使用h ...

  7. LeetCode Summary Ranges (统计有序数列范围)

    题意:给出个有序不重复数列(可能负数),用缩写法记录这个数列. 思路:找每个范围的起始和结束即可. class Solution { public: vector<string> summ ...

  8. 【转】iOS中设置导航栏标题的字体颜色和大小

    原文网址:http://www.360doc.com/content/15/0417/11/20919452_463847404.shtml iOS中设置导航栏标题的字体颜色和大小,有需要的朋友可以参 ...

  9. Hibernate4.x之映射文件

    POJO类和数据库的映射文件*.hbm.xml POJO类和关系数据库之间的映射可以用一个XML文档来定义 通过POJO类的数据库映射文件,Hibernate可以理解持久化类和数据库表之间的对应关系, ...

  10. system CPU占用率过高与91助手的关系

    今天正在认真工作,忽然发现电脑越来越慢. 按 CTRL+ALT+DEL打开任务管理器看了下CPU使用率.其中system占用率居然达到了64%.不对劲儿,按照平时习惯,system根本占用了不要这么多 ...