Bug 44523 - Select Sheet Tab does not work correctly
Summary: Select Sheet Tab does not work correctly
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.2-FINAL
Hardware: PC Windows Vista
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2008-03-04 02:57 UTC by Michael
Modified: 2009-10-02 11:36 UTC (History)
0 users

Original File (Sheet 1 selected) (14.00 KB, application/vnd.ms-excel)
2008-03-04 04:07 UTC, Michael
POI Outputfile (Sheet 3 displayed but tab not selected) (13.00 KB, application/vnd.ms-excel)
2008-03-04 04:39 UTC, Michael
Correct file (POI output should look like this) (13.00 KB, application/vnd.ms-excel)
2008-03-04 04:40 UTC, Michael
sample code re-testing bug fix (7.98 KB, application/octet-stream)
2009-10-02 11:12 UTC, Josh Micich

Note You need to log in before you can comment on or make changes to this bug.
Description Michael 2008-03-04 02:57:40 UTC
I'd like to programmatically select a sheet with the following function:


The sheet with index 2 is displayed correctly but its "sheet tab" on the left bottom corner doesn't seem to be selected (actually no tab is selected...).
A selected tab is usually displayed with a white background color.

Comment 1 Nick Burch 2008-03-04 03:01:23 UTC
I'm guessing we're not setting all the records we need to then

Can you upload three files:
* the original file, with some other tab selected
* the file with tab 2 selected by poi
* the file with tab 2 selected by excel

Ideally, could you also use biffviewer to spot the difference between them? Clearly one or two records aren't being updated that need to be, so we need to identify these records (by comparing the 3 files)
Comment 2 Michael 2008-03-04 04:07:06 UTC
Created attachment 21618 [details]
Original File (Sheet 1 selected)
Comment 3 Michael 2008-03-04 04:39:22 UTC
Created attachment 21619 [details]
POI Outputfile (Sheet 3 displayed but tab not selected)

FileOutputStream out = new FileOutputStream("test_hmi.xls");
InputStream input = RunImport.class.getResourceAsStream( "simple.xls" );
POIFSFileSystem fs = new POIFSFileSystem( input );
HSSFWorkbook wb = new HSSFWorkbook(fs);
// Select last sheet


// Note that sheet 3 is displayed in the output file but its tab is not correctly selected (sheet 1 remains selected)
Comment 4 Michael 2008-03-04 04:40:00 UTC
Created attachment 21621 [details]
Correct file (POI output should look like this)
Comment 5 Josh Micich 2008-05-15 16:35:58 UTC
Fixed in svn r656893

Looks like some confusion between sheet selection and focus (starting in WINDOW2 record).

Added new method setActiveSheet(int) to HSSFWorkbook.
Changed comment on selSelectedTab(int) to emphasise distinction from setActiveSheet
Added new method setSelectedTabs(int[]) for multiple tab(sheet) selection.
Added new methods / deprecated old methods with misleading names.
Added junit test cases.
Comment 6 Shibaram Sahoo 2009-10-01 12:57:37 UTC
I confirm, I am facing the same problem.
It's not fixed.
In same scenario, after copying a old workbook from then adding a sheet to it and saving it. And setting the new sheet as Active is not working.

I tried below both ways.			


But none is working.

Comment 7 Shibaram Sahoo 2009-10-01 13:12:28 UTC
Neither this works too :(

Comment 8 Shibaram Sahoo 2009-10-01 13:14:59 UTC
Neither this works too :(

Comment 9 Josh Micich 2009-10-02 11:12:36 UTC
Created attachment 24337 [details]
sample code re-testing bug fix

This code shows adding a new sheet to an existing workbook, and setting it both 'active' and 'selected'.

More extensive junits were added with the bug-fix in svn r657136 .
Comment 10 Josh Micich 2009-10-02 11:36:46 UTC
You haven't supplied enough details to make it clear what is going wrong, so it is difficult to guess what mistake you have made.

Perhaps you are using POI 3.0 or earlier.  The fix was available from version 3.1 onwards.

Perhaps you haven't read the javadoc properly.  Note - in the typical scenario both wb.setActiveSheet(ix) and wb.setSelectedTab(ix) need to be called.  It's not clear whether you tried this.  In any case you should have seen the proper effects of calling either method in isolation.

Perhaps you've found some more complex use-case which re-creates the bug in version 3.1 or later.  If you are certain you have working code that calls both these methods and creates a workbook with the wrong sheet active or selected, please upload that example (like attachment (id=24337)) to demonstrate your assertion.