Bug 46663

Summary: Calling shiftRows on a xlsx file corrupts the workbook
Product: POI Reporter: Vinu Kumar <vinu.kumar>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.5-dev   
Target Milestone: ---   
Hardware: PC   
OS: Windows Server 2003   
Attachments: Repro file for the issue
xlsx file used for testing

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