Bug 46654

Summary: "Unable to read file" after "shiftRows"
Product: POI Reporter: Matthew <matthew.knl>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: major    
Priority: P2    
Version: 3.5-dev   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: Testing file

Description Matthew 2009-02-02 19:35:09 UTC
Created attachment 23215 [details]
Testing file

I use following codes to open an Excel file, then call "sheet.shiftRows", but the output file cannot be opened by MS Excel. It prompted "Unable to read file." error message.
--
HSSFWorkbook wb = new HSSFWorkbook(ExcelUtil.fixInputStream(new FileInputStream("unable_to_read_file.xls")));
HSSFSheet sheet = wb.getSheet("Other");
sheet.shiftRows(12, 165, 12, false, true);
wb.write(new FileOutputStream("unable_to_read_file.output.xls"));
--
Please use the attached file for testing, thanks a lot!
Comment 1 Josh Micich 2009-02-04 23:53:14 UTC
Fixed in svn r741036 (and svn r741037 )

The example spreadsheet you supplied has incorrect values in RowRecord firstCol & lastCol.  Excel has no problem with those values being wrong, except when no cells are present.  POI wasn't properly updating these indexes the newly emptied row.  This problem has been fixed and a junit has been added.

Some extra confusion was noticed regarding cell comments (HSSFComment).  It seems like the firstCol and lastCol fields of RowRecord need to take cell comments into account.  POI does not do this yet.  Some significant restructuring might be required to make that work properly.