poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 53877] New: POI 3.8 error attempting to program a "delete columns" capability
Date Sat, 15 Sep 2012 16:15:09 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=53877

          Priority: P2
            Bug ID: 53877
          Assignee: dev@poi.apache.org
           Summary: POI 3.8 error attempting to program a "delete columns"
                    capability
          Severity: normal
    Classification: Unclassified
          Reporter: everymoment@comcast.net
          Hardware: PC
            Status: NEW
           Version: 3.8
         Component: HSSF
           Product: POI

Created attachment 29380
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=29380&action=edit
Demonstrates an error, possibly in HSSFrow.moveCell()

The attached java file POI_error_in_column_deletes.java attempts to demonstrate
one way to program column deletes in POI 3.8. This java program does the
following: 
  - creates a new workbook
  - creates 10 rows each containing 10 empty cells
  - fills in range A3:E3 with "A", "B", "C", "D", and "E"
  - runs code designed to delete columns B and C,
      but instead of getting ADE in the third row it gets ACE
  - outputs a workbook testDeleteColumns.xls

It get the same incorrect result in POI 3.8 and in the
poi-3.9-beta1-20120915.jar nightly.

The inner loop of deleting columns, which contains the error, is the method
deleteColumnFromRow:


/** Removes a cell at START_COL and shifts remainder of row to the left by one.
 * @param row row from which to delete and shift cells
 * @param START_COL index of cell to remove
 */
private static void deleteColumnFromRow(HSSFRow row, final int START_COL){
    if(START_COL >= COLS){
        return;
    }
    HSSFCell check = row.getCell(START_COL);
    if(null!=check){
        row.removeCell(check);
    }
    System.err.println(
        "        deleteColumnFromRow: row = "+
        row.getRowNum());
    HSSFCell cell = null;
    for(int col = START_COL+1; col < COLS; col++){
        int source = col;
        int destination = col-1;
        cell = row.getCell(source);
        if(null != row.getCell(destination)){
            row.removeCell(row.getCell(destination));
            // Because the API says the destination cannot exist,
            // the destination has been deleted. The API reference is
            //
poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFRow.html
        }
        if(null != cell){
            // I THINK THE ERROR MIGHT BE IN moveCell().
            row.moveCell(cell,(short)(destination));
        }
    }
}

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Mime
View raw message