The maximum number of cell styles was exceeded. You can define up to 4000 styles
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
-------------示例--------------
错误示例
改正后正确代码
- 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);
- }
以上方法原地址: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即可。
- public HSSFCellStyle createCellStyle()
- {
- if(workbook.getNumExFormats() == MAX_STYLES) {
- throw new IllegalStateException("The maximum number of cell styles was exceeded. " +
- "You can define up to 4000 styles in a .xls workbook");
- }
- ExtendedFormatRecord xfr = workbook.createCellXF();
- short index = (short) (getNumCellStyles() - 1);
- HSSFCellStyle style = new HSSFCellStyle(index, xfr, this);
- workbook.createCellXFExt(index);
- return style;
- }
IE兼容问题
数字形式写入代码
- public static Cell writeNumericValue(Sheet sheet, int row, int column,
- Double value) {
- Row poiRow = sheet.getRow(row);
- if (poiRow == null) {
- poiRow = sheet.createRow(row);
- }
- Cell poiCell = poiRow.getCell(column);
- if (poiCell != null) {
- poiRow.removeCell(poiCell);
- }
- poiCell = poiRow.createCell(column);
- poiCell.setCellType(Cell.CELL_TYPE_NUMERIC);
- poiCell.setCellValue(value);
- return poiCell;
- }
写入日期代码
- public static Cell writeDateValue(Workbook book, Sheet sheet, int row,
- int column, Date value) {
- Row poiRow = sheet.getRow(row);
- CreationHelper createHelper = book.getCreationHelper();
- if (poiRow == null) {
- poiRow = sheet.createRow(row);
- }
- Cell poiCell = poiRow.getCell(column);
- if (poiCell == null) {
- poiCell = poiRow.createCell(column);
- }
- CellStyle cellStyle = book.createCellStyle();
- cellStyle.setDataFormat(createHelper.createDataFormat().getFormat(
- "yyyy-mm-dd"));
- if (value != null) {
- poiCell.setCellValue(value);
- } else {
- poiCell.setCellValue(new Date());
- }
- poiCell.setCellStyle(cellStyle);
- return poiCell;
- }
以上方法原地址:http://realgodo.iteye.com/blog/1105529
The maximum number of cell styles was exceeded. You can define up to 4000 styles的更多相关文章
- 【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 ...
- Failed to connect to database. Maximum number of conections to instance exceeded
我们大体都知道ArcSDE的连接数有 48 的限制,很多人也知道这个参数可以修改,并且每种操作系统能支持的最大连接数是不同的. 如果应用报错:超出系统最大连接数 该如何处理? 两种解决办法: 第一,首 ...
- Exceeded maximum number of retries. Exceeded max scheduling attempts 3 for instance
Exceeded maximum number of retries. Exceeded max scheduling attempts 3 for instance
- 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 ...
- openstack-HTTP exception thrown: Maximum number of ports exceeded错误解决方案
最近几天什么都没动无法创建云主机了,经过一番查询 1.查日志 /data/jumpserver/logs 得到错误 HTTP exception thrown: Maximum number of p ...
- 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 ...
- "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 ...
- 错误: 实例 "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 ...
- ORA-00019: maximum number of session licenses exceeded 超出最大会话许可数
ORA-00019: maximum number of session licenses exceededORA-00019: 超出最大会话许可数 Cause: All licenses ...
随机推荐
- Miles per gallon to kilometers per liter
Miles per gallon to kilometers per liter 1 Imperial Gallon = 4.54609188 litres 1 Mile = 1.609344 kil ...
- fiddler代理
对于前段开发人员,fiddler 是一个必不可少的调试神器.下载地址:http://www.telerik.com/download/fiddler. 有同学也许会碰到,chrome 下 fiddle ...
- Webform——Repeater多表联合显示
对于一个表里,通过外键连接如何显示另一个表的数据,前Winform里可以用封装类来实现. 对于Webform,可以用封装类,也可以用Repeater的ItemDataBound事件(//在项被绑定数据 ...
- Java [leetcode 11] Container With Most Water
问题描述: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ...
- 在.net中用Connection对象数据源的架构信息
可得到数据库中的,表,视图,等信息 string strcon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + fi ...
- Visual Studio中的一些较大的文件的作用
1.sdf 这些是工程中的中间,用于预编译等作用,最终可执行文件是不需要的,默认情况下,删除后重新编译还会生成.如果不需要,在Visual Studio里进入如下设置: 进入"Tools & ...
- web.xml 配置的详解
http://my.oschina.net/u/1383439/blog/224448 http://blog.csdn.net/guihaijinfen/article/details/836383 ...
- 020自动化测试 PK 手动测试
一.手工测试为什么不可替代 手工测试是不可替代的,因为人是具有很强只能判断能力的,而工具是相对机械缺乏思维能力的东西 工具是人开发出来的 二.手工测试不可替代的表现 测试用例的设计:需要tester有 ...
- 备份 VPS 上得内容到国内
起源: 最近毕设快开题了,校园网进入了收费测试的阶段,得把车辆的数据库 down 下来.发现国内 down 的速度真心慢呢.于是乎使用了在美国的 VPS 来 down,果不其然,30M 左右的下载速度 ...
- MSP430的看门狗常见用法以及中断函数的书写方法
今天下午看了一下MSP430的看门狗的基本用法 看门狗是为了防止程序跑飞而设定的,但是由于看门狗是一个类似于定时器,因此可以把他当作定时器来使用 示例代码:用看门狗定时器使一个led闪烁 #inclu ...