0

我的代码在 excel 中生成了搜索字符串veri_tipi,以查找和获取匹配的文本值。但是,如果列具有相似的值,假设我的字符串是"aaaa"并且单元格具有aaaa bbbbb,它将替换最后找到的结果。

如果我理解正确,我需要的是打破 while 循环。有人可以帮我弄清楚这之后该怎么做吗?

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;

                                }

                                } 

            }

                  }

        }
4

2 回答 2

0

而不是while(cellIterator.hasNext()),您应该使用:

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

    ...
}
于 2013-07-23T07:37:27.833 回答
-1

您实际上可以使用标签。例子

myLoop:
while( boolean ) {

    if( true ) {

        break myLoop;

    }

}
于 2013-07-26T07:18:12.877 回答