POI 操作Excel 设置样式的问题,最多设到1212行

大家好,本人用POI循环生成Excel单元格。设置每个单元格的样式。主要代码如下:

for (Sa sa: saList) {

HSSFCell ctnmCell = row.createCell(cellCount++);
ctnmCell.setCellStyle([color=red]getTextStyle(wb));[/color]
ctnmCell.setCellValue(null == sa.getCtnm() ? "--" : sa.getCtnm());

HSSFCell csnmCell = row.createCell(cellCount++);
csnmCell.setCellStyle([color=red]getTextStyle(wb));[/color]
csnmCell.setCellValue(null == sa.getCsnm() ? "--" : sa.getCsnm();

HSSFCell ctntCell = row.createCell(cellCount++);
ctntCell.setCellStyle([color=red]getTextStyle(wb)[/color]);
ctntCell.setCellValue(null == sa.getCtnt() ? "--" : sa.getCtnt());

........// 后面还有很多Cell, 每行27个。
}

private HSSFCellStyle getTextStyle(HSSFWorkbook wb) {
HSSFCellStyle textStyle = wb.createCellStyle();
textStyle.setVerticalAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION);
textStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
textStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
textStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
textStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
textStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
HSSFDataFormat df = wb.createDataFormat();
textStyle.setDataFormat(df.getFormat("@"));
textStyle.setWrapText(true);
return textStyle;
}

在每行27列的情况下,最多设到1212行的中间。之后的数据就设不上样式了。请问是什么原因?如何解决。

PS:之前我用JXL的时候,也碰到过类似的问题,结果,按照网上修改了一下源代码,解决了。

补充一下,是对于一个文档中的HSSFCellStyle个数有限制的。这个限制在MS的OFFICE的EXcel中就有。

对于其它的一样的样式的,使用相同的样式即可:
[code="java"]
HSSFCellStyle cellStyle = getTextStyle(wb);

ctntCell.setCellStyle(cellStyle);
csnmCell.setCellStyle(cellStyle);
[/code]

对于HSSFCellStyle是有限制的。

使用如下的代码:
[code="java"]
HSSFCellStyle cellStyle = getTextStyle(wb);
ctntCell.setCellStyle(cellStyle);
[/code]

同样,对于字体也是有限制的。

仔细看一下apache poi doc文档,是有说明的。