Bug 17759 - [PATCH][RFE]Add a way to change the displayed sheet in usermodel API
Summary: [PATCH][RFE]Add a way to change the displayed sheet in usermodel API
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 2.0-dev
Hardware: All All
: P3 minor with 1 vote (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-03-07 04:14 UTC by Toshiaki Kamoshida
Modified: 2006-07-25 05:06 UTC (History)
0 users



Attachments
Testcase to find this problem.Please do it and open "Output.xls" with Excel Application. (810 bytes, text/plain)
2003-03-07 04:16 UTC, Toshiaki Kamoshida
Details
PATCH to fix (with some Proposals) (1.92 KB, patch)
2003-05-08 09:07 UTC, Toshiaki Kamoshida
Details | Diff
PATCH to do it. (1.29 KB, patch)
2003-05-20 07:13 UTC, Toshiaki Kamoshida
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Toshiaki Kamoshida 2003-03-07 04:14:35 UTC
When you call HSSFSheet#setSelected(boolean) to change the selected sheet,
and save the workbook and open with Excel Application,you will see it;

1."selected tab" is changed to the sheet as you call the method.
2.but the sheet "currently showing" is not the sheet tab selecting.

Secondly,if you call HSSFSheet#setSelected(false) to all sheets,you can make 
the workbook with selecting no sheet.
It isn't good interface,I feel.I feel the parameter of the method should 
be "void" and works like HSSFSheet#setSelected(true).
Comment 1 Toshiaki Kamoshida 2003-03-07 04:16:26 UTC
Created attachment 5196 [details]
Testcase to find this problem.Please do it and open "Output.xls" with Excel Application.
Comment 2 Toshiaki Kamoshida 2003-05-08 09:07:42 UTC
Created attachment 6265 [details]
PATCH to fix (with some Proposals)
Comment 3 Toshiaki Kamoshida 2003-05-08 09:16:41 UTC
I searched the way to fix it,and found;

To change the selection correctly,we must cange both WindowOneRecord stored at
Workbook and WindowTwoRecord stored at Sheet.

So,we can't make the method for this function at HSSFSheet,but only at 
HSSFWorkbook.

Plz test and eval the PATCH with the testcase a little changed from I submitted.

<s2.setSelected(true);
>b.setSelectedSheet("Sheet1");
or
>b.setSelecteSheetAt((short)1);

Regards.
Comment 4 Toshiaki Kamoshida 2003-05-08 09:32:32 UTC
I know there is an another way,
Add an instance-field "the reference to parent Workbook object" at Sheet,
and once the event to send other Sheets or Workbook happend at a Sheet(like  
Sheet#setSelected(boolean)),the method send the event by using the reference.

I feel it is cool,but I don't know we can cange the reference-structure of 
objects or not...
Comment 5 Toshiaki Kamoshida 2003-05-20 04:43:16 UTC
Sorry,I didn't know that we can select multiple sheet-tabs with "ctrl+mouse 
click"etc. at Excel XP.So this proposal is invalid.Please forget the 
attatchments id=5196 & id=6265.

But "There is no way to change the displayed sheet with usermodel APIs" is an 
another problem.Please add a way to do it.
I found that we can do it with hssf.record.WindowOneRecord#setSelectedTab(short)
Comment 6 Toshiaki Kamoshida 2003-05-20 07:13:15 UTC
Created attachment 6416 [details]
PATCH to do it.
Comment 7 Toshiaki Kamoshida 2003-05-20 07:17:19 UTC
Please apply the PATCH and execute it and check Test1.xls and Test2.xls with 
Excel Application.

import java.io.FileOutputStream;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class Test {
	public static void main(String[] args) throws Exception{
		HSSFWorkbook book = new HSSFWorkbook();
		HSSFSheet s1 = book.createSheet("Test1");
		HSSFSheet s2 = book.createSheet("Test2");
		book.write(new FileOutputStream("Test1.xls"));
		s1.setSelected(false);
		s2.setSelected(true);
		book.setSelectedSheet("Test2");
		book.write(new FileOutputStream("Test2.xls"));
	}
}
Comment 8 Jason Height 2006-07-25 12:06:23 UTC
It appears that a variant of the patch 6416 was applied at some stage, but this
bug never closed. The method HSSFWorkbook.setSelectedTab is now available & it
does what the bug decribes.

Closing....

Jason