You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2004/08/12 22:44:33 UTC

DO NOT REPLY [Bug 30635] New: - HSSFRow.getLastCellNum() is out by one

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=30635>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=30635

HSSFRow.getLastCellNum() is out by one

           Summary: HSSFRow.getLastCellNum() is out by one
           Product: POI
           Version: 2.5
          Platform: All
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: HSSF
        AssignedTo: poi-dev@jakarta.apache.org
        ReportedBy: apache@allegory.demon.co.uk


I'm just starting with POI and wrote a simple program to read a spreadsheet.
The attached program displays incorrect values for HSSFRow.getLastCellNum().
It is too large by 1.  The problem appears to be in RowRecord where 
field_3_last_col has a "// +1" comment by it but that is too deep for me.

The spreadsheet came from US gov statistics and can be supplied upon request, 
however it is several megabytes.

(BTW, you don't have NetBSD as OS in bugzilla)

Bob

import java.io.*;

import org.apache.poi.hssf.usermodel.*;

public class EG {

    public static void main(String[] args)
                            throws IOException {
        FileInputStream fis = new FileInputStream(args[0]);

        HSSFWorkbook wb = new HSSFWorkbook(fis);

        System.out.println("#sheets = " + wb.getNumberOfSheets());

        HSSFSheet sheet = wb.getSheetAt(1);

        System.out.println("#rows = " + (1+sheet.getLastRowNum()));

        HSSFRow row = sheet.getRow(9);
        short firstCellNum = row.getFirstCellNum();
        short lastCellNum = row.getLastCellNum();

        System.out.println("first col = " + firstCellNum);
        System.out.println("last col  = " + lastCellNum);

        System.out.println();

        for (short j=firstCellNum; j < lastCellNum; j++) {
            HSSFCell cell = row.getCell(j);
            String str = null;

            switch (cell.getCellType()) {

                case HSSFCell.CELL_TYPE_STRING:
                    str = cell.getStringCellValue().trim();
                    break;

                case HSSFCell.CELL_TYPE_NUMERIC:
                    str = String.valueOf(cell.getNumericCellValue());
                    break;

            }

            System.out.println("cell[" + j + "] = " + str);
        }

    }
}

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