我在excel中有一个表,其中有很多行。我使用apache poi应用了一组过滤条件,并读取了表数据。我需要在列上应用新的过滤条件,但是我已经删除了(?)已经设置的过滤条件。
workSheet.setAutoFilter(CellRangeAddress.valueOf("A21:K21"));
final CTAutoFilter sheetFilter = workSheet.getCTWorksheet().getAutoFilter();
final CTFilterColumn filterColumn1 = sheetFilter.addNewFilterColumn();
filterColumn1.setColId(column[0]);
final CTFilterColumn filterColumn2 = sheetFilter.addNewFilterColumn();
filterColumn2.setColId(column[1]);
final CTFilter filter1 = filterColumn1.addNewFilters().insertNewFilter(0);
filter1.setVal(value[0]);
final CTFilter filter2 = filterColumn2.addNewFilters().insertNewFilter(0);
filter2.setVal(value[1]);
for(int rowNum = rowIndex; rowNum < workSheet.getPhysicalNumberOfRows(); rowNum++){
XSSFRow row = workSheet.getRow(rowNum);
for(int colNum = colStartIndex; colNum < colEndIndex; colNum++){
XSSFCell cellValue = row.getCell(colNum);
if ((cellValue.getColumnIndex() == column[0] && (!value[0].contains(getCellValue(cellValue)))) || (cellValue.getColumnIndex() == column[1] && (!value[1].contains(getCellValue(cellValue))))) {
if (row.getRowNum() != rowIndex) { // skip header
row.getCTRow().setHidden(true);
}
}
}
}
请帮助我如何删除过滤器。