我想从列F中的值为1的excel中删除所有行,并将其保存在java代码中的新excel中。我的java代码如下。新的excel正在创建,但我无法删除列F中值为1的所有行。我的java代码是:
final String filterValue = "1";
FileInputStream excelFile = new FileInputStream("Users.xls");
System.out.println("File read successfully!!");
HSSFWorkbook wb = new HSSFWorkbook(excelFile);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFWorkbook wb2 = new HSSFWorkbook();
wb2 = wb;
Row row;
row = sheet.getRow(0);
int getLastCell=row.getLastCellNum()-1;
int lastIndex = sheet.getLastRowNum();
for (int i=0; i<=lastIndex; i++){
row=sheet.getRow(i);
if(row.getCell(getLastCell)!=null && (row.getCell(getLastCell).equals(filterValue)))
{
System.out.println("Removing row "+row);
sheet.removeRow(row);
//sheet.shiftRows(i, lastIndex, -1);
}
FileOutputStream fileOut = new FileOutputStream("FilteredUserList.xls");
wb2.write(fileOut);
fileOut.close();
}