Bug 46654 - "Unable to read file" after "shiftRows"
Summary: "Unable to read file" after "shiftRows"
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.5-dev
Hardware: PC Windows XP
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2009-02-02 19:35 UTC by Matthew
Modified: 2009-02-04 23:53 UTC (History)
0 users

Testing file (36.50 KB, application/vnd.ms-excel)
2009-02-02 19:35 UTC, Matthew

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