Bug 46663 - Calling shiftRows on a xlsx file corrupts the workbook
Summary: Calling shiftRows on a xlsx file corrupts the workbook
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.5-dev
Hardware: PC Windows Server 2003
: P2 normal with 2 votes (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-04 02:43 UTC by Vinu Kumar
Modified: 2009-02-12 20:10 UTC (History)
0 users



Attachments
Repro file for the issue (1.00 KB, application/octet-stream)
2009-02-04 02:43 UTC, Vinu Kumar
Details
xlsx file used for testing (8.17 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2009-02-04 02:44 UTC, Vinu Kumar
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vinu Kumar 2009-02-04 02:43:58 UTC
Created attachment 23226 [details]
Repro file for the issue

Read an xlsx file and call shiftRows. Write the resultant workbook to a file and open in MS office 2007.

Office throws the following error "Excel found unreadable content." and asks for recovering. Following recovery message is thrown:

Removed Records: Cell information from /xl/worksheets/sheet1.xml part

The row gets shifted but it shifts the first column and last column is lost.
Comment 1 Vinu Kumar 2009-02-04 02:44:29 UTC
Created attachment 23227 [details]
xlsx file used for testing
Comment 2 Vinu Kumar 2009-02-04 22:06:20 UTC
fixed by modifying the following code is in XSSFCell.java

 protected void modifyCellReference(XSSFRow row) {
        this.cell.setR(new CellReference(row.getRowNum(), cellNum).formatAsString());

        CTCell[] ctCells = row.getCTRow().getCArray();
        for (CTCell ctCell : ctCells) {
            ctCell.setR(new CellReference(row.getRowNum(), cellNum).formatAsString());
        }
    }

with this:


protected void modifyCellReference(XSSFRow row) {
     
       int cnum = 0;
        this.cell.setR(new CellReference(row.getRowNum(), cnum).formatAsString());

        CTCell[] ctCells = row.getCTRow().getCArray();
        for (CTCell ctCell : ctCells) {
            ctCell.setR(new CellReference(row.getRowNum(), cnum++).formatAsString());
        }
    }
Comment 3 Vinu Kumar 2009-02-12 20:10:01 UTC
This is fixed in the latest trunk