Bug 40548 - Exception in ExternSheetRecord while setting Repeating Rows and Columns
Summary: Exception in ExternSheetRecord while setting Repeating Rows and Columns
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.0-dev
Hardware: All other
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2006-09-19 16:50 UTC by Rich Renomeron
Modified: 2008-12-29 16:06 UTC (History)
1 user (show)

Spreadsheet that causes the exception (73.00 KB, application/octet-stream)
2006-09-19 16:56 UTC, Rich Renomeron
Java code for testing (1.83 KB, text/plain)
2006-09-19 16:58 UTC, Rich Renomeron
Output from non-crashing code (79.00 KB, application/octet-stream)
2006-12-31 10:41 UTC, Andy Oliver
updated test case to generate foobar.xls attachment (now writes output) (1.99 KB, text/plain)
2006-12-31 10:43 UTC, Andy Oliver
patch to fix this problem (1.12 KB, patch)
2006-12-31 10:47 UTC, Andy Oliver
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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
	at org.apache.poi.hssf.model.Workbook.getSheetIndexFromExternSheetIndex
	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
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.