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

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 包括poi全部jar

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

    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 。本来想免费,但是苦于没积分所以...

    解决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. See "systemctl status sshd.service" and "journalctl -xe" for details. 问题2:程序sftp登陆不上 低版本的连接工具无法连接,现有程序sftp到...

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

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

    微软内部资料-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 ...

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

    详解 Java Maximum redirects (100) exceeded

    主要介绍了详解 Java Maximum redirects (100) exceeded的相关资料,需要的朋友可以参考下

    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最大值

    Maximum最大值

    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通过在网上搜索...

    ESD和EOS培训教程.pdf

    This exposure may or may not result in a catastrophic failure of the item." Typically, it can be inferred that an overstress has occurred when an item fails to meet its electrical characteristics....

    文件和进程隐藏与检测

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

    jxl操作excel以及jar 解决导出报错问题.rar

    导入导出、合并单元格处理代码示例 jar包解决导出Excel 出现的问题:Warning: Maximum number of format records exceeded. Using default format.

    Effect of Film/Regenerative Cooling on Scramjet Engine Performance

    Film cooling was modeled to allow performance prediction of scramjet engine design. The model was based on experimental results of the compressible mixing layer for the vicinity of the injection slot,...

    How to Cheat at Configuring Open Source Security Tools

    See how to define your wireless network boundaries, and monitor to know if they're being exceeded and watch for unauthorized traffic on your network. *Covers the top 10 most popular open source ...

Global site tag (gtag.js) - Google Analytics