我一直在使用 Apache POI 并使用我的这段代码:
private void remove() {
HSSFWorkbook wb = null;
HSSFSheet sheet = null;
try {
FileInputStream is = new FileInputStream("C:/juni.xls");
wb = new HSSFWorkbook(is);
sheet = wb.getSheetAt(0);
for (Row row : sheet) {
for (Cell cell : row) {
if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
if (cell.getRichStringCellValue().getString().trim().contains("POST")) {
row_count_post_1 = row.getRowNum();
DashBoard.txt.setText("Processed the STRING \"POST\" on Row#" + row_count_post_1);
HSSFRow removingRow = sheet.getRow(row_count_post_1);
if (removingRow != null) {
sheet.removeRow(removingRow);
}
int lastIndex = sheet.getLastRowNum();
sheet.shiftRows(row_count_post_1 + 1, lastIndex, -1);
} else {
break;
}////////////want to break from here;
}
}
}
} catch (Exception e) {
//do catch for no exception
}
}
if
问题是当我的语句停止工作时我想退出循环。如果我不使用我的else
. 实际上,如果此代码无法找到一个字符串,它应该停止,但在我的情况下,else 突然与我的 if 一起工作,在这种情况下只会发生一次迭代。请告诉我我做错了什么,我只需要提示而不是整体帮助。提前致谢