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

解决样式多问题 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 立即下载
AI摘要

本文介绍使用Apache POI库进行大批量数据导出到Excel的方法,包括如何避免达到4000种样式的限制,提供正确的代码示例,并解决IE浏览器兼容性问题。

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

 

以上方法原地址:http://blog.youkuaiyun.com/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兼容问题

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

数字形式写入代码

	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

 

 

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 。本来想免费,但是苦于没积分所以要了5分 见谅 。实在没积分的话可以给我发邮件,给你送一个,呵呵 立即下载

相关推荐

Windows C语言编程:Beep API实现蜂鸣器原理与实战

如果你在 Windows 上写过 C 语言程序,想给程序加个简单的提示音,第一个想到的可能是 printf("\a") 。这个转义字符确实能在某些终端里发出“嘀”的一声,但它太原始、太不可控了,而且很多时候根本没声音。那么,有没有一种更“Windows”、更可控、更专业的方法来让你的程序“说话”呢? 答案是肯定的,而且它比你想象的要强大和复杂。Windows 提供了一个名为 Beep 的 API 函数,专门用于生成蜂鸣声。你可能觉得这功能太简单,甚至有点过时——不就是让电脑“哔”一声吗?但恰恰是这个看似简单

weixin_34109408的博客 394

java excel 字体大小_java操作Excel的poi的字体设置

package com.java.poi;import org.apache.poi.hssf.usermodel.HSSFWorkbook;import org.apache.poi.ss.usermodel.*;import java.io.FileOutputStream;/*** 字体设置* @author nidegui* @create 2019-06-17 11:30*/public...

weixin_29800175的博客 3200

有了网段为什么还要有VLAN???

近几日,在学习VLAN及VXLAN方面的知识,对于产生原因做一个总结及详解。 VLAN(Virtual Local Area Network,虚拟局域网),其主要用途是用来缩小广播域,即进行隔离。 先对广播域的一个概念做如下描绘:如下图,主机A、B、C、D均连接在交换机SW1上,其中A、C同网段为192.168.252网段,而B和D同网段,为192.168.250网段。 现,假如A与C第...

dandandean_96的博客 6885

The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook

Caused by: java.lang.IllegalStateException: The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook 最近在写excel导出功能是,要求按照不同的成品进行sheet分页。需要按照将第一个模板复制多份 需要循环多

by_lucky_seven的博客 4897

峰岹FU6832L双核电机控制芯片实战:从FOC算法到BLDC/PMSM驱动开发

在嵌入式系统和电机控制领域,磁场定向控制(FOC)是实现无刷直流电机(BLDC)和永磁同步电机(PMSM)高效、平稳运行的核心算法。其原理是通过坐标变换将三相交流量分解为直流量,实现类似直流电机的转矩与磁场解耦控制,从而提升效率、降低噪音与振动。这项技术的工程价值在于能以更低的处理器开销实现高性能驱动,广泛应用于消费电子、工业自动化与智能家电。本文以峰岹FU6832L芯片为例,深入解析其独特的双核架构——将实时性要求极高的FOC运算交由专用硬件引擎处理,解放主控CPU处理应用逻辑,并结合PID参数整定、电流

weixin_29570795的博客 508

【WILEY】wiley期刊投稿详解:从revision到Accepted全流程实例讲解

注意:包括没标注修改位置的word文件和标注了修改位置的word文件。

Everyday try to become better -Kobe Bryant 1万+

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.crea

leys123的专栏 4665

OpenCV安装配置教程VS2022(超级顺利)

博主最开始没打算写这篇博客,只是想简单的在网上找一下最新版的OpenCV的安装配置教程,适用于VS2022的,但是我搜了一早上,也没搜到一个能让我成功安装配置的,看了很多很多文章,根本就没有几篇有用的。所以没办法了,只能自己研究了,于是就整理了这篇博客,希望能帮到和我一样的人,这就是博主一直信奉的利他精神!

weixin_47367099的博客 5万+

c#使用Npoi 提示 Excel导出报错 The maximum number of cell styles was exceeded. You can define up to 4000

在使用NPOI 导出EXCEL的时候 提示 The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook 出现此问题 原因如下: private static void SetFontSize(IFont font,IWorkbook wk,string co...

sd6275832ght的博客 3185

基于Cesium移动的天空云

天空中的云朵也算是一种天气气候的效果,它能更加逼真的反映当前的天气状况,可以是白云朵朵,也可以是乌云密布,结合其他天气效果,可以组合形成较为真实的三维可视化场景。

星云数海的博客,一个专注GIS十多年的GISer人。 446

2023全国职业技能大赛 网络系统管理 服务部署 Linux部分--基础配置

服务器和客户端基本配置如下表,各虚拟机已预装系统。一、关闭防火墙和Selinux。七、需要使用到的命令详解。三、修改root密码。

weixin_62926639的博客 998

JAVA POI The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls

[10:11:09:013] [ERROR] - xxx.xxx.security.common.handler.GlobalExceptionHandler.otherExceptionHandler(GlobalExceptionHandler.java:102) - The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook java.lang.RuntimeEx

weixin_43939924的博客 773

华为OD机试 新系统真题-收集灵草(Java/Py/C++/Go/C/Js)

华为OD机试 新系统真题【收集灵草】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题【收集灵草】多语言题解。

qq_45776114的博客 544

【转】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...

weixin_33766168的博客 278

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Excel导出报错 You can define up to 4000 styles in a .xls workbook

导出 Excel数据多报错:java.lang.IllegalStateException: The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook  代码创建的cellSyle太多了。在循环中调用了HSSFCellStyle cellStyle = w

A_银河之光 1万+

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

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

使用POI导出xls文件,由于数据过多,导致导出xls报错如下: The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook   原因: 代码中创建 HSSFCellStyle cellStyle = hssfWorkbook.createCellS...

weixin_34368949的博客 632

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

上一篇: 在Eclipse中Debug 为什么显示source not found
下一篇: ERROR 1130: Host 192.168.88.160 is not allowed to connect to this MySQL server
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值