Our application programmatically sets certain rows as header columns for printing purposes, and makes use of the setRepeatingRowsAndColumns() method of HSSFWorkbook to accomplish this. However, on certain spreadsheets, that method throws an exception similar to the following: java.lang.ArrayIndexOutOfBoundsException: -1 at java.util.ArrayList.get(Unknown Source) at org.apache.poi.hssf.record.ExternSheetRecord.getREFRecordAt (ExternSheetRecord.java:122) at org.apache.poi.hssf.model.Workbook.getSheetIndexFromExternSheetIndex (Workbook.java:1799) at org.apache.poi.hssf.usermodel.HSSFWorkbook.findExistingRowColHeaderNameRecordId x(HSSFWorkbook.java:730) at org.apache.poi.hssf.usermodel.HSSFWorkbook.findExistingRowColHeaderNameRecord (HSSFWorkbook.java:717) at org.apache.poi.hssf.usermodel.HSSFWorkbook.setRepeatingRowsAndColumns (HSSFWorkbook.java:650) at com.tcg.Bug6839TestHarness.main(Bug6839TestHarness.java:44) We *think* that this happens in spreadsheets with pre-existing print areas, but we're not sure. We have observed this behavior in both 2.5.1 final and the 3.0alpha2. Test case and example spreadsheet to come.
Created attachment 18886 [details] Spreadsheet that causes the exception Here's an example spreadsheet that causes the exception when HSSFWorkbook.setRepeatingRowsAndColumns() is run on it.
Created attachment 18887 [details] Java code for testing Java class that shows the error. Run the example spreadsheet with this.
Created attachment 19333 [details] Output from non-crashing code This is the output from my patch that I will commit shortly.
Created attachment 19334 [details] updated test case to generate foobar.xls attachment (now writes output) Updated test case based on attachment 18887 [details] which takes output file (and writes it)
The problem was caused by HSSF set Repeating Rows/Cols function (BTW that function has a repugnantly cryptic interface, we should make friendlier helper functions that do the -1 magic for you). It didn't take into account "global" "NAME" records with a "0" in field 6 (thus we ended up looking for sheet record -1). this patch ignores globals when using the extern sheet ref function.
Created attachment 19335 [details] patch to fix this problem patch that fixes problem (committed after further testing)
(fix to fulfill a bunisoft support contract)
Assuming that this is fixed. HSSFWorkbook has been refactored and this patch whether actually applied or not, is no longer relevant. Please advise if this needs further work.