Bug 50853 - Auto-size usage can seriously limit row count
Summary: Auto-size usage can seriously limit row count
Status: RESOLVED DUPLICATE of bug 49188
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.6-FINAL
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2011-03-02 08:19 UTC by Bancika
Modified: 2011-03-03 03:57 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
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.

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

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.



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