Bug 40548

Summary: Exception in ExternSheetRecord while setting Repeating Rows and Columns
Product: POI Reporter: Rich Renomeron <rich.renomeron>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: poi-support
Priority: P2    
Version: 3.0-dev   
Target Milestone: ---   
Hardware: All   
OS: other   
Attachments: Spreadsheet that causes the exception
Java code for testing
Output from non-crashing code
updated test case to generate foobar.xls attachment (now writes output)
patch to fix this problem

Description Rich Renomeron 2006-09-19 16:50:58 UTC
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.
Comment 1 Rich Renomeron 2006-09-19 16:56:01 UTC
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.
Comment 2 Rich Renomeron 2006-09-19 16:58:04 UTC
Created attachment 18887 [details]
Java code for testing

Java class that shows the error.  Run the example spreadsheet with this.
Comment 3 Andy Oliver 2006-12-31 10:41:59 UTC
Created attachment 19333 [details]
Output from non-crashing code

This is the output from my patch that I will commit shortly.
Comment 4 Andy Oliver 2006-12-31 10:43:22 UTC
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)
Comment 5 Andy Oliver 2006-12-31 10:46:52 UTC
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. 
Comment 6 Andy Oliver 2006-12-31 10:47:50 UTC
Created attachment 19335 [details]
patch to fix this problem

patch that fixes problem (committed after further testing)
Comment 7 Andy Oliver 2006-12-31 10:50:16 UTC
(fix to fulfill a bunisoft support contract)
Comment 8 David Fisher 2008-12-29 16:06:38 UTC
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.