我一直在尝试开发一个可以删除包含特定字符串“POST”的多行的代码。我一直在这样做:
private void processExcelFile(File f_path){
File path=f_path;
HSSFWorkbook wb = null;
try{
FileInputStream is=new FileInputStream(path);
wb= new HSSFWorkbook(is);
HSSFSheet sheet = wb.getSheetAt(0);
int j = 0;
for(Row row: sheet){
for(Cell cell : row){
count++;
if (cell.getCellType() == Cell.CELL_TYPE_STRING){
if (cell.getRichStringCellValue().getString().trim().contains("POST")){
rowcount_post=row.getRowNum();
System.out.print("ROW COUNT= "+rowcount_post);
HSSFRow removingRow = sheet.getRow(rowcount_post);
if (removingRow != null) {
sheet.removeRow(removingRow);
}
}
}
}
}
} catch(Exception e){
JOptionPane.showMessageDialog(this,e.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
}
try{
FileOutputStream fileOut = new FileOutputStream("C:/juni.xls");
wb.write(fileOut);
} catch(Exception e) {
JOptionPane.showMessageDialog(this,e.getMessage(),"SAVE Error",JOptionPane.ERROR_MESSAGE);
}
}
事实上,它一次只删除一行。我可以删除所有包含字符串 POST 的行吗?