Bug 46953

Summary: Incorrect HSSFWorkbook.getNumberOfSheets() and corrupt Excel file
Product: POI Reporter: Matthew <matthew.knl>
Component: HSSFAssignee: POI Developers List <dev>
Severity: critical CC: kumar.naveen
Priority: P2    
Version: 3.5-dev   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: problem.xls

Description Matthew 2009-04-01 22:46:04 UTC
Created attachment 23435 [details]

I use following codes to read attached "problem.xls" Excel file, the Excel file contains 5 worksheets but HSSFWorkbook.getNumberOfSheets() output 1 only. And write the workbook out, it cannot be opened by MS Excel.


FileInputStream fis = new FileInputStream("problem.xls");
POIFSFileSystem poifs = new POIFSFileSystem(fis);
HSSFWorkbook wb = new HSSFWorkbook(poifs);		
System.out.println("wb.getNumberOfSheets() = " + wb.getNumberOfSheets());
FileOutputStream os = new FileOutputStream("problem.output.xls");
Comment 1 Matthew 2009-04-01 22:46:50 UTC
Created attachment 23436 [details]
Comment 2 Yegor Kozlov 2009-04-04 06:30:17 UTC
Looks like a regression introduced in r757520.
If I comment out the line 229 then the number of sheets is 5 and the output is readable by Excel.

The offending line:

Josh, please confirm the bug. 

Comment 3 Matthew 2009-04-23 19:43:37 UTC
Since this bug is a blocker in our current project, is there any update on this bug? Thanks a lot.
Comment 4 Josh Micich 2009-05-10 14:50:53 UTC
Fixed in svn r773412

junit added

It seems like this bug was evident in existing test samples, but the junits were not checking the number of sheets in those cases.  This change is just another band-aid.  The code is long overdue for refactoring the chart/user-view stuff into dedicated RecordAggregate sub-classes.
Comment 5 Josh Micich 2009-05-15 11:11:48 UTC
*** Bug 47199 has been marked as a duplicate of this bug. ***