You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "Andrew C. Oliver" <ac...@apache.org> on 2003/01/24 10:38:02 UTC

Re: / /OREF:CPTD81A3 When reading excel ss I can't pick up the the cells of the first column

There is an error in you use of iterators. next afvances the row, you're calling it twice.  Same with cells.

while (rows.hasNext() ) {
  HSSFRow row = (HSSFRow) rows.next();
  Iterator cells = row.cellIterator();
  while (cells.hasNext() {
    cell = (HSSFCell) cells.next();
  }
}

Your for statement advances 2 cells and 2 rows...  (see below)

   for( HSSFRow row = (HSSFRow) rows.next(); rows.hasNext(); row
= (HSSFRow) rows.next() ) {
    System.out.println( "Row #" + row.getRowNum() );
    // Iterate over each cell in the row and print out the cell's
content
     Iterator cells = row.cellIterator();
      for( HSSFCell cell = (HSSFCell) cells.next(); cells.hasNext();
cell = (HSSFCell) cells.next() ) {



ZTofie@za.safmarine.com wrote:

>Hi and thanks in advance for any and all your time...
>
>I am working through a PIO example (yup I'm a first time user).
>Using the code as is results in the contents of the first cell of
>each row not being printed (it's supposed to print the contents of
>each cell for the row under iteration).
>
>Could someone please tell me why this is happening?
>In my mind, the problem seems to be at the inner for loop that
>iterates over the cells.
>
>   for( HSSFRow row = (HSSFRow) rows.next(); rows.hasNext(); row
>= (HSSFRow) rows.next() ) {
>    System.out.println( "Row #" + row.getRowNum() );
>    // Iterate over each cell in the row and print out the cell's
>content
>     Iterator cells = row.cellIterator();
>      for( HSSFCell cell = (HSSFCell) cells.next(); cells.hasNext();
>cell = (HSSFCell) cells.next() ) {
>
>It is obvious that the cell pointer is moved to the next cell in the
>row before the cell contents are processed in the body of the loop.
>Could someone please point me in the right direction?
>Is there something obvious that I'm missing or maybe a better way of
>implementing the iteration over the cells?
>
>Many thanks in advance
>Zain
>
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
>  
>