/** * The maximum number of cell styles in a .xls workbook. * The 'official' limit is 4,000, but POI allows a slightly larger number. * This extra delta takes into account built-in styles that are automatically * * See http://office.microsoft.com/en-us/excel-help/excel-specifications-and-limits-HP005199291.aspx */ privatestaticfinalint MAX_STYLES = 4030;
/** * Create a new Cell style and add it to the workbook's style table. * You can define up to 4000 unique styles in a .xls workbook. * * @return the new Cell Style object * @throws IllegalStateException if the number of cell styles exceeded the limit for this type of Workbook. */ @Override public HSSFCellStyle createCellStyle() { if(workbook.getNumExFormats() == MAX_STYLES) { thrownew IllegalStateException("The maximum number of cell styles was exceeded. " + "You can define up to 4000 styles in a .xls workbook"); } ExtendedFormatRecord xfr = workbook.createCellXF(); short index = (short) (getNumCellStyles() - 1); returnnew HSSFCellStyle(index, xfr, this); }
/** * Excel2007 * * <ul> * <li>The total number of available rows is 1M (2^20)</li> * <li>The total number of available columns is 16K (2^14)</li> * <li>The maximum number of arguments to a function is 255</li> * <li>Number of conditional format conditions on a cell is unlimited * (actually limited by available memory in Excel)</li> * <li>Number of cell styles is 64000</li> * <li>Length of text cell contents is 32767</li> * <ul> */ EXCEL2007(0x100000, 0x4000, 255, Integer.MAX_VALUE, 64000, 32767);
// Is this right? Number formats (XSSFDataFormat) and cell styles (XSSFCellStyle) are different. What's up with the plus 1? privatestaticfinalint MAXIMUM_STYLE_ID = SpreadsheetVersion.EXCEL2007.getMaxCellStyles();
public XSSFCellStyle createCellStyle(){ if (this.getNumCellStyles() > MAXIMUM_STYLE_ID) { thrownew IllegalStateException("The maximum number of Cell Styles was exceeded. You can define up to " + MAXIMUM_STYLE_ID + " style in a .xlsx Workbook"); } else { int xfSize = this.styleXfs.size(); CTXf xf = org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf.Factory.newInstance(); xf.setNumFmtId(0L); xf.setFontId(0L); xf.setFillId(0L); xf.setBorderId(0L); xf.setXfId(0L); int indexXf = this.putCellXf(xf); returnnew XSSFCellStyle(indexXf - 1, xfSize - 1, this, this.theme); } }