就会报以下的错误,是由于cell styles太多create造成,故一般可以把cellstyle设置放到循环外面
报错如下:
Caused by: : The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook
at (:1144)
at (:88)
at (:612)
at (:112)
at (:190)
at (:856)
at .invoke0(Native Method)
at (:39)
at (:25)
at (:597)
at (:191)
at (:276)
at (:68)
at (:88)
... 33 more
-------------示例--------------
错误示例
改正后正确代码
CellStyle style = ();
Font font = ();
(Font.BOLDWEIGHT_BOLD);
(font);
for (int i = 0; i < 10000; i++) {
Row row = (i);
Cell cell = ((short) 0);
(style);
}
以上方法原地址:/hoking_in/article/details/7919530
方法二(不推荐,影响性能):
1.4000最大样式错误
: The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook错误
找到中修改createCellStyle函数内的最大样式数量即可。重新打即可。
public HSSFCellStyle createCellStyle()
{
if(() == 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 = ();
short index = (short) (getNumCellStyles() - 1);
HSSFCellStyle style = new HSSFCellStyle(index, xfr, this);
(index);
return style;
}
IE兼容问题
数字形式写入代码
public static Cell writeNumericValue(Sheet sheet, int row, int column,
Double value) {
Row poiRow = (row);
if (poiRow == null) {
poiRow = (row);
}
Cell poiCell = (column);
if (poiCell != null) {
(poiCell);
}
poiCell = (column);
(Cell.CELL_TYPE_NUMERIC);
(value);
return poiCell;
}
写入日期代码
public static Cell writeDateValue(Workbook book, Sheet sheet, int row,
int column, Date value) {
Row poiRow = (row);
CreationHelper createHelper = ();
if (poiRow == null) {
poiRow = (row);
}
Cell poiCell = (column);
if (poiCell == null) {
poiCell = (column);
}
CellStyle cellStyle = ();
(().getFormat(
"yyyy-mm-dd"));
if (value != null) {
(value);
} else {
(new Date());
}
(cellStyle);
return poiCell;
}
以上方法原地址:/blog/1105529