Having a 3250 rows x 10 cells for each row seem to be the limit the number of styles. 3500 x 10 breaks the excel file. Attached is a set of files/code to replicate the issue.
Created attachment 28750 [details] java code and excel template to reproduce the error
In HSSF, we have a maximum number of styles, and throw an exception if someone tries to add more than that /** * 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 * created for new workbooks * * See http://office.microsoft.com/en-us/excel-help/excel-specifications-and-limits-HP005199291.aspx */ private static final int MAX_STYLES = 4030; The .xlsx file format also has a maximum number of styles, but it doesn't look like we enforce that in the same way. From a quick check, neither XSSFWorkbook.createCellStyle() nor StylesTable appears to have the check The fix is probably for someone to dig out the official maximum number of styles in a .xlsx file, from the file format docs, then implement a similar check in xssf
According to http://msdn.microsoft.com/en-us/library/office/ff700514.aspx the maximum number of styles for Excel 2010 is 64000 .
We have fixed the checks for the limits as part of bug 58260, see r1696586, I think this one should be fixed as well through this, please report a new bug with sample code if you still run into problems. But note that usually styles should be re-used if possible as there are hard limits of how many styles Excel will accept. *** This bug has been marked as a duplicate of bug 58260 ***