excel导出 Maximum number of fonts was exceeded异常

原创
2016/08/19 16:11
阅读数 3.3K
                 for(int j = 0;j<data.length;j++){
	        		  HSSFCell cell = row.createCell(j);  
	        		  cell.setCellStyle(style2);
	        		  String value = data[j];
	        		  HSSFRichTextString richString = new HSSFRichTextString(value);  
                      HSSFFont font3 = workbook.createFont();  
                      font3.setColor(HSSFColor.BLUE.index);  
                      richString.applyFont(font3);  
                      cell.setCellValue(richString);  
	        	  }

 

HSSFRichTextString richString = new HSSFRichTextString(value);  
         HSSFFont font3 = workbook.createFont();

这两行代码一定要写到循环外面,因为excel导出最多只支持32767个font

源码如下

public HSSFFont createFont()
{
    /*FontRecord font =*/ workbook.createNewFont();
    short fontindex = (short) (getNumberOfFonts() - 1);

    if (fontindex > 3)
    {
        fontindex++;   // THERE IS NO FOUR!!
    }
    if(fontindex == Short.MAX_VALUE){
        throw new IllegalArgumentException("Maximum number of fonts was exceeded");
    }

    // Ask getFontAt() to build it for us,
    //  so it gets properly cached
    return getFontAt(fontindex);
}
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部