Bug 46953 - Incorrect HSSFWorkbook.getNumberOfSheets() and corrupt Excel file
Summary: Incorrect HSSFWorkbook.getNumberOfSheets() and corrupt Excel file
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.5-dev
Hardware: PC Windows XP
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2009-04-01 22:46 UTC by Matthew
Modified: 2009-05-15 11:11 UTC (History)
1 user (show)

problem.xls (46.50 KB, application/vnd.ms-excel)
2009-04-01 22:46 UTC, Matthew
problem.output.xls (46.00 KB, application/vnd.ms-excel)
2009-04-01 22:46 UTC, Matthew

Note You need to log in before you can comment on or make changes to this bug.
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. ***