Bug 49874

Summary: Problems with names when removing a sheet from an HSSF workbook
Product: POI Reporter: Martin Studer <martin.studer>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED WORKSFORME    
Severity: normal    
Priority: P2    
Version: 3.7-dev   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Zip file with the mentioned workbooks (Test.xls and Test.xlsx)

Description Martin Studer 2010-09-03 02:51:29 UTC
Created attachment 25979 [details]
Zip file with the mentioned workbooks (Test.xls and Test.xlsx)

I have an Excel file with three sheets called AAA, BBB, CCC. On each of them there is a name defined: AA on AAA, BB on BBB, CC on CCC. If I'm now removing sheet BBB, the behaviour for a HSSF workbook is different than for a XSSF workbook. The following is what I observe:

- HSSF: Sheets AAA and CCC remain (which is ok), but left are only names AA and BB. This is strange. I would understand if BB would be missing but CC should definitely still be around I guess. Also, if you open the file with an older version of Excel (< 2007) you are confronted with a dialog saying that the file has been repaired. Excel 2007+ seems to do that behind the scenes.

- XSSF: Sheets AAA and CCC remain (again, this is ok), and so do the names AA and CC. This behaviour seems ok to me.

Please find a snippet of code that can be used to reproduce the problem:


Workbook wb = WorkbookFactory.create(new FileInputStream("C:/Users/mstuder/Documents/Test.xls"));
wb.removeSheetAt(wb.getSheetIndex("BBB"));
wb.write(new FileOutputStream("C:/Users/mstuder/Documents/Test2.xls"));

Also, please find attached the two corresponding Excel files (*.xls and *.xlsx).

OS: Windows 7
POI: 3.7-beta2
Java: 1.6.0_20 64-bit
Comment 1 awm 2010-12-23 20:19:00 UTC
As of last night's trunk AA, BB, and CC all appear in xlsx version after BBB is deleted.  I didn't try the OLE2.

I think leaving the BB named range is the proper outcome.