Bug 27622 - Named range reference becomes invalid on removeSheet
Summary: Named range reference becomes invalid on removeSheet
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 2.0-FINAL
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2004-03-12 08:24 UTC by Simon Niederberger
Modified: 2008-08-05 15:57 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Simon Niederberger 2004-03-12 08:24:07 UTC
(1) My workbook has sheets SHA, SHB, SHC, ...
(2) Create a named range pointing to e.g. SHD!$A$2:$A$16
(3) Delete some sheets (not SHD, of course)
(4) The named range now points to e.g. SHA!$A$2:$A$16

From taking a glimpse at HSSFName, I guess named ranges are internally linked 
to the sheet nidex rather than the name. I guess when running 
workbook.removeSheet, the indexes of the named ranges are not update (or 
something like that)
NOTE: haven't tried release 2.5, maybe it's already fixed there.

Thanks nd good luck
Comment 1 Simon Niederberger 2004-03-15 19:55:42 UTC
Here's the source code (snippet) [works with a workbook containing sheets 
SHA ... SHG]

			// **** CREATE NAMED RANGE **** 
			int idxRange = _book.getNameIndex("MYRANGE");
			HSSFName name;
			if (idxRange == -1) {
				name = _book.createName();
			else {
				name = _book.getNameAt(idxRange);

			// **** DELETE SOME SHEETS **** 
			int idxSheet;
			idxSheet = _book.getSheetIndex("SHB");
			if (idxSheet > 0) {
			idxSheet = _book.getSheetIndex("SHF");
			if (idxSheet > 0) {

... and MYRANGE will point to SHD!$A$2:$A$8 (instead of SHC).

Current workaround is to first delete the sheets, then create the range, so 
the bug fix isn't really urgent.
Comment 2 Yegor Kozlov 2008-05-17 04:33:35 UTC
Could you please try poi-3.1-beta1 and report if the problem still persists? 

Comment 3 Simon Niederberger 2008-05-20 07:54:24 UTC
Sorry, I've moved to a different project in the meantime and don't have the original source code available.
Comment 4 Nick Burch 2008-08-05 15:57:54 UTC
Guessing this is now fixed. Please re-open the bug if it still occurs on re-testing with a recent version (eg 3.1), if you do happen to find the source to test against again