0

My code has generated the search string veri_tipi in excel to find and get text values that match. But if the column has similar values, lets say my string is "aaaa" and the cell has aaaa bbbbb, it replaces the last found result.

What I need, if I understand correctly, is to break the while loop. Can someone help me figure out what to do after this?

if (cell.getStringCellValue().equals(veri_Tipi)){ 

                            CellReference nextCellAdress = new CellReference(row.getRowNum(),cell.getColumnIndex()+2);

                            Row next_Cell_Row = sheet.getRow(nextCellAdress.getRow());
                            Cell next_Cell = next_Cell_Row.getCell(nextCellAdress.getCol());

while(rowIterator.hasNext() ) {


       Row row = rowIterator.next();

        //For each row, iterate through each columns

       Iterator<Cell> cellIterator = row.cellIterator();



        while(cellIterator.hasNext()){

            Cell cell = cellIterator.next();

            switch(cell.getCellType()) {
                case Cell.CELL_TYPE_BOOLEAN:
               //     System.out.print(cell.getBooleanCellValue() + "\t\t");
                    break;
                case Cell.CELL_TYPE_NUMERIC:
                   // System.out.print(cell.getNumericCellValue() + "\t\t");
                    break;
                case Cell.CELL_TYPE_STRING:
              if (cell.getStringCellValue().equals(veri_Tipi)){ 

                                CellReference nextCellAdress = new CellReference(row.getRowNum(),cell.getColumnIndex()+2);

                                Row next_Cell_Row = sheet.getRow(nextCellAdress.getRow());
                                Cell next_Cell = next_Cell_Row.getCell(nextCellAdress.getCol());



                switch(next_Cell.getCellType()) {
                case Cell.CELL_TYPE_BOOLEAN:

                    break;
                case Cell.CELL_TYPE_BLANK:

                     break;
                case Cell.CELL_TYPE_NUMERIC:

                    bilancoVeriExcel =next_Cell.getNumericCellValue();
                    String strDouble = String.valueOf((bilancoVeriExcel));

                    myList_DoubleHash.add(strDouble);
                    myListHash.add(cell.getStringCellValue());

                    System.out.print(myListHash+"\n");
                    System.out.print(myList_DoubleHash+"\n");
                    System.out.print(myList_DoubleHash.size()+"\n");

                    break;
                 case Cell.CELL_TYPE_STRING:

                    break;

                                }

                                } 

            }

                  }

        }
1
  • Note : The logic of code to find, string, then move 2nd next cell in the row and get the value Jul 22, 2013 at 18:52

2 Answers 2

0

Instead of while(cellIterator.hasNext()), you should use:

for (int cellNo = 0; cellNo < row.getLastCellNum(); cellNo++){

    ...
}
-1

You could actually use a label. Example

myLoop:
while( boolean ) {

    if( true ) {

        break myLoop;

    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.