public Sheet filterSheet(Sheet sheetToFilter){ if(sheetToFilter == null){ System.out.println("sheetToFilter is null!"); return null; } int lastRowNum = sheetToFilter.getLastRowNum(); int rowIndexI = 0; int rowIndexJ = 0; while(rowIndexI<=lastRowNum){ Row row = sheetToFilter.getRow(rowIndexI); if(row != null){ if(isVaildRow(row)){ if(rowIndexI>rowIndexJ){ shiftRows(rowIndexI,rowIndexI,rowIndexJ-rowIndexI); } rowIndexJ++; } else{ removeRow(row); } } rowIndexI++; } }
虽然能完成功能,但涉及到shiftRows和removeRows,复杂度过高。。。。不推荐使用