You might have a look at XLS2CSVmra (uses HSSF for Excel 2003 and earlier available from POI examples area), or my own XLSX2CSV (uses XSSF for Excel 2007 available at http://chris-lott.org/software). Both demonstrate how to get every row/column from an Excel file. You could pare that down to just 1 cell relatively easily. Unfortunately the HSSF version depends on a POI feature that currently suffers from a severe bug as documented here https://issues.apache.org/bugzilla/show_bug.cgi?id=45672

HTH

chris...

Otis HARRISON wrote:
Hi, this is what i am doing so far to just view every line

            ArrayList cellArrayHolder = new ArrayList();
            System.out.println("Inside readClassesExcelFile()");

            try {
System.out.println(fileName);
                FileInputStream myInput = new FileInputStream(fileName);
                System.out.println("Got File");
                /** Create a POIFSFileSystem object* */
                POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);

                /** Create a workbook using the File System* */
                HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);

                /** Get the first sheet from workbook* */
                HSSFSheet mySheet = myWorkBook.getSheetAt(0);
                System.out.println("Worksheet"+mySheet);

                /** We now need something to iterate through the cells.* */
                Iterator rowIter = mySheet.rowIterator();
                System.out.println("rowIter.hasNext() =
"+rowIter.hasNext());
                while (rowIter.hasNext()) {
                    HSSFRow myRow = (HSSFRow) rowIter.next();
                    Iterator cellIter = myRow.cellIterator();

                    ArrayList cellStoreArray = new ArrayList();
                    while (cellIter.hasNext()) {
                        HSSFCell myCell = (HSSFCell) cellIter.next();
System.out.println("The Value of myCell is
:"+myCell.toString());
                        cellStoreArray.add(myCell.toString());


                    }
                    cellArrayHolder.add(cellStoreArray);
                }
            } catch (Exception e) {
                // e.printStackTrace();
                e.printStackTrace(System.out);
                System.exit(0);
            }
            return cellArrayHolder;
Thank you for all the help


MSB wrote:
Yes, that is quite possible. There is no pre-existing method to suport
this so you will have to write your own code to accomplish the task
however.

I have not had to do something like this yet and have not tested the
following so please do not take it as read that everything will work
perfectly. Further, you do not say which file format you are targetting -
binary or OpenXML - so I am writing this code using the HSSF stream, the
binary one.

int colNumber = 2;  // Index for column C
int startRowNum = 2;    // Index for row number 3
int lastRowNum = 0;
File file = new File("... your file .....");
FileInoputStream fis = new FileInputStream(file);
HSSFWorkbook workbook = new HSSFWorkbook();
int numSheets = workbook.getNumberOfSheets();
for(int i = 0; i < numSheets; i++) {
    HSSFSheet sheet = workbook.getSheetAt(i);
    lastRowNum = sheet.getLastRowNum;
    for(int j = startRowNum; j < lastRowNum; j++) {
        HSSFCell cell = sheet.getRow(j).getCell(colNumber);
        switch(cell.getCellType()) {
           case HSSFCell.CELL_TYPE_STRING:
               System.out.println("Got a String type Cell.");
System.out.println(cell.getRichStringCellValue().getString());
           // And you cxan extend this to handle the other types of cells,
           // numeric, formula, error, boolean and blank. Check out the
           // Quick Guide and how to if you are at all unsure.
        }
    }
}



Otis HARRISON wrote:
Hi, I have a quick question about Poi and Hssf. I was wondering if you
can specify a specific column and just grab that data. Then just keep
going down that row until you reach the end. I am trying to go down, let
say Column B row 11 and keep going down until i reach column B row 54109.
I just want to put all those values into an array and just have to mess
with the array. Thank alot for any help you can give.




---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to