Summary: | [PATCH][RFE]Add a way to change the displayed sheet in usermodel API | ||
---|---|---|---|
Product: | POI | Reporter: | Toshiaki Kamoshida <kamoshida.toshiaki> |
Component: | HSSF | Assignee: | POI Developers List <dev> |
Status: | RESOLVED FIXED | ||
Severity: | minor | ||
Priority: | P3 | ||
Version: | 2.0-dev | ||
Target Milestone: | --- | ||
Hardware: | All | ||
OS: | All | ||
Attachments: |
Testcase to find this problem.Please do it and open "Output.xls" with Excel Application.
PATCH to fix (with some Proposals) PATCH to do it. |
Description
Toshiaki Kamoshida
2003-03-07 04:14:35 UTC
Created attachment 5196 [details]
Testcase to find this problem.Please do it and open "Output.xls" with Excel Application.
Created attachment 6265 [details]
PATCH to fix (with some Proposals)
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. 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... 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) Created attachment 6416 [details]
PATCH to do it.
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")); } } 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 |