Document Solutions for Excel, Java Edition | Document Solutions
Features / Slicer / Use Do Filter Operation
In This Topic
    Use Do Filter Operation
    In This Topic

    DsExcel Java enables users to apply filters to slicers, thus enabling users to analyse bulk information in a spreadsheet quickly and effectively.

    Use slicer do-filter operation

    In order to use slicer to perform do-filter operation, refer to the following example code.

    Java
    Copy Code
    // Adding data to the table
    worksheet.getRange("A:F").setColumnWidth(15);
    worksheet.getRange("A1:F16").setValue(sourceData);
    ITable table = worksheet.getTables().add(worksheet.getRange("A1:F16"), true);
    table.getColumns().get(3).getDataBodyRange().setNumberFormat("$#,##0.00");
    
    // Create slicer cache for the table.
    ISlicerCache cache = workbook.getSlicerCaches().add(table, "Category", "categoryCache");
    
    // Add slicer for table
    ISlicer slicer1 = cache.getSlicers().add(workbook.getWorksheets().get("Sheet1"), "cate1", 
    "Category", 30, 550, 100, 200);
    
    // Execute the do filter operation. Here we are filtering vegetables.
    slicer1.getSlicerCache().getSlicerItems().get("Vegetables").setSelected(false);

    Clear slicer filter

    In order to clear slicer filter, refer to the following example code.

    Java
    Copy Code
    // Adding data to the table
    worksheet.getRange("A:F").setColumnWidth(15);
    worksheet.getRange("A1:F16").setValue(sourceData);
    ITable table = worksheet.getTables().add(worksheet.getRange("A1:F16"), true);
    table.getColumns().get(3).getDataBodyRange().setNumberFormat("$#,##0.00");
    
    // Create slicer cache for table.
    ISlicerCache cache = workbook.getSlicerCaches().add(table, "Category", "categoryCache");
    
    // Add slicer for table
    ISlicer slicer1 = cache.getSlicers().add(workbook.getWorksheets().get("Sheet1"), "cate1", 
    "Category", 30, 550, 100, 200);
    
    // Execute the do filter operation. Here we are filtering vegetables.
    slicer1.getSlicerCache().getSlicerItems().get("Vegetables").setSelected(false);
    
    // Clear the slicer filter.
    slicer1.getSlicerCache().clearAllFilters();