Bug 53209 - Too many styles corrupts the excel
Summary: Too many styles corrupts the excel
Status: RESOLVED DUPLICATE of bug 58260
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.8-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2012-05-09 19:32 UTC by awm
Modified: 2015-09-03 19:28 UTC (History)
0 users

java code and excel template to reproduce the error (265.42 KB, application/x-zip-compressed)
2012-05-09 19:34 UTC, awm

Note You need to log in before you can comment on or make changes to this bug.
Description awm 2012-05-09 19:32:09 UTC
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.
Comment 1 awm 2012-05-09 19:34:06 UTC
Created attachment 28750 [details]
java code and excel template to reproduce the error
Comment 2 Nick Burch 2012-05-09 21:35:04 UTC
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
Comment 3 Nikel 2012-08-07 19:00:49 UTC
According to http://msdn.microsoft.com/en-us/library/office/ff700514.aspx the maximum number of styles for Excel 2010 is 64000 .
Comment 4 Dominik Stadler 2015-09-03 19:28:40 UTC
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 ***