Updating Slicer

Possible Usage Scenarios

If you want to update slicer in Microsoft Excel, select or unselect its items, it will then update the slicer table or pivot table accordingly. Please use Slicer.SlicerCache.SlicerCacheItems to select or unselect slicer items with Aspose.Cells and then call Slicer.refresh() method to update the slicer table or pivot table. 

Updating Slicer

The following sample code loads the sample Excel file that contains an existing slicer. It unselects the 2nd and 3rd items of the slicer and refreshes the slicer. It then saves the workbook as the output Excel file. The following screenshot shows the effect of the sample code on the sample Excel file. As you can see in the screenshot, refreshing the slicer with selected items has also refreshed the pivot table accordingly.

todo:image_alt_text

Sample Code

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Load sample Excel file containing slicer.
Workbook wb = new Workbook(srcDir + "sampleUpdatingSlicer.xlsx");
// Access first worksheet.
Worksheet ws = wb.getWorksheets().get(0);
// Access the first slicer inside the slicer collection.
Slicer slicer = ws.getSlicers().get(0);
// Access the slicer items.
SlicerCacheItemCollection scItems = slicer.getSlicerCache().getSlicerCacheItems();
// Unselect 2nd and 3rd slicer items.
scItems.get(1).setSelected(false);
scItems.get(2).setSelected(false);
// Refresh the slicer.
slicer.refresh();
// Save the workbook in output XLSX format.
wb.save(outDir + "outputUpdatingSlicer.xlsx", SaveFormat.XLSX);