Bug 50853

Summary: Auto-size usage can seriously limit row count
Product: POI Reporter: Bancika <stormbringer>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED DUPLICATE    
Severity: normal    
Priority: P2    
Version: 3.6-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description Bancika 2011-03-02 08:19:37 UTC
Excel 2003 has 64K row limit and I can export up to 64K rows using POI, but only if I don't use sheet.autoSizeColumn(i) method.

Here's a simple example that leads to this problem: try to create a sheet with over 33K rows (I used 34K) and a single column. When data is written, call sheet.autoSizeColumn to auto-fit the column and it breaks with this exception.

java.lang.ArrayIndexOutOfBoundsException: -32732
        at java.util.ArrayList.get(ArrayList.java:324)
        at org.apache.poi.hssf.model.WorkbookRecordList.get(WorkbookRecordList.java:50)
        at org.apache.poi.hssf.model.Workbook.getExFormatAt(Workbook.java:787)
        at org.apache.poi.hssf.usermodel.HSSFCell.getCellStyle(HSSFCell.java:906)
        at org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn(HSSFSheet.java:1727)
        at org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn(HSSFSheet.java:1662)

When there are more columns it breaks even sooner than that. My usecase has ~50 columns and it breaks even with 2K rows. It looks like it uses short int data type and it goes out of range.

Let me know if you need more info.

Cheers
Comment 1 Nick Burch 2011-03-02 08:26:19 UTC
Can you try with a recent svn nightly build? Only there have been some auto size fixes since 3.6, and you might find it's already been sorted
Comment 2 Bancika 2011-03-02 09:05:48 UTC
Just tried with poi-3.8-beta1-20110302 and it still fails :(
Comment 3 Yegor Kozlov 2011-03-03 03:57:46 UTC
poi-3.8-beta1-20110302 fails, but with a different exception!

You are creating too many cell styles. The maximum number of cell styles in a workbook is 4000, see
http://office.microsoft.com/en-us/excel-help/excel-specifications-and-limits-HP005199291.aspx

Cell Styles must be shared. Do not create per-cell, otherwise you will get a
“Too many styles” error in Excel when opening your workbook. Think of Cell
Styles like CSS and create them like that.

http://poi.apache.org/faq.html#faq-N100EF

Yegor

*** This bug has been marked as a duplicate of bug 49188 ***