我试图使用 CTAutoFilter 过滤一列。表(样本表,不是实际的)值如下:
Brand Color Round Neck
Louis Philippe White Yes
Peter England White Yes
Van Huesen White No
Arrow New York White No
我想过滤值为“是”的第三列。所以我写了下面的代码。但我得到空指针异常
CTFilterColumn myFilterColumn=sheetFilter.insertNewFilterColumn(0);
代码是:
try
{
xlsxFile = new FileInputStream("D:/Automation/Sample1.xlsx");
xssfWB = new XSSFWorkbook(xlsxFile);
sheet = xssfWB.getSheetAt(0);
CTAutoFilter sheetFilter=sheet.getCTWorksheet().getAutoFilter();
CTFilterColumn myFilterColumn=sheetFilter.insertNewFilterColumn(0);
myFilterColumn.setColId(3L);
CTFilter myFilter = myFilterColumn.addNewFilters().insertNewFilter(0);
myFilter.setVal("Yes");
for(Row r : sheet)
{
for(Cell c : r)
{
if (c.getColumnIndex()==3 && !c.getStringCellValue().equals("Yes"))
{
row = (XSSFRow) c.getRow();
if(row.getRowNum()!=0)
{
row.getCTRow().setHidden(true);
}
}
}
}
}
谁能帮我解决这个问题??