我的代码在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;
}
}
}
}
}
答案 0 :(得分:0)
而不是while(cellIterator.hasNext())
,您应该使用:
for (int cellNo = 0; cellNo < row.getLastCellNum(); cellNo++){
...
}
答案 1 :(得分:-1)
您实际上可以使用标签。实施例
myLoop:
while( boolean ) {
if( true ) {
break myLoop;
}
}