Null Pointer Exception while using insertNewFilterColoumn method

302 views Asked by At

I was trying to filter one Column using CTAutoFilter. The table (sample table, not the actual one ) value is as follows :

Brand           Color   Round Neck
Louis Philippe  White   Yes
Peter England   White   Yes
Van Huesen      White   No
Arrow New York  White   No

I want to filter the 3rd coloumn with the value "Yes". So I wrote the following code. But I'm getting null pointer exception on

CTFilterColumn  myFilterColumn=sheetFilter.insertNewFilterColumn(0);

The code is :

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);
                    }
                }
            }
        }


    }

can anyone help me to sort this out??

0

There are 0 answers