`
Hermosa_Young
  • 浏览: 254544 次
  • 来自: 上海
社区版块
存档分类
最新评论

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

    博客分类:
  • Java
阅读更多

在用POI导出Excel表格时,报如下错误:

 

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

 

原因:style创建次数太多。

 

改进方法:现在循环外,创建style,然后在循环中再用样式。

 

修改前代码,如下所示,当数据不是很大时,系统不会提示出错,但当数据很大时,就会报错。

 

public class CellValue {

	public static HSSFWorkbook setValue (ExcelEntity g) {
		List<LinkedHashMap<String,Object>> list = g.getList();
		HSSFWorkbook workbook = g.getWb();
		/*HSSFSheet sheet = workbook.getSheet(g.getStr());*/
		HSSFSheet sheet = workbook.getSheetAt(0);
		for(int i=0;i<list.size();i++) {
		
			LinkedHashMap<String,Object> map3 = list.get(i);
	    	HSSFRow contentRow = sheet.createRow(i+4);
	    	int j=0;
			for (Iterator<String> it =  map3.keySet().iterator();it.hasNext();)	{
			
				Object key = it.next();
				HSSFCell NameContent = contentRow.createCell(j);
				System.out.println(map3.get(key));
				NameContent.setCellValue((String)map3.get(key));
				NameContent.setCellStyle(ExcelStyle.getContentStyle(workbook)); 
				j++;
			}   
		}
		return workbook;
	}
}

 

修改后代码:

 

HSSFCellStyle contentStyle = ExcelStyle.getContentStyle(workbook);
		
for(int i=0;i<list.size();i++) {
	
	LinkedHashMap<String,Object> map3 = list.get(i);
	HSSFRow contentRow = sheet.createRow(i+4);
	int j=0;
	for (Iterator<String> it =  map3.keySet().iterator();it.hasNext();)	{
			
		Object key = it.next();
		HSSFCell NameContent = contentRow.createCell(j);
		System.out.println(map3.get(key));
		NameContent.setCellValue((String)map3.get(key));
		NameContent.setCellStyle(contentStyle); 
		j++;
	}
}

 

0
0
分享到:
评论

相关推荐

    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