Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Updating a slicer means filtering the data of the pivot table or table that the slicer is connected to. Aspose.Cells for Python via Java updates the slicer and recalculates the linked pivot table or table directly from the filter items:
Slicer.selectItems(labels, append) — selects the specified labels and recalculates the linked pivot table or table. When append is True, the originally selected labels are kept and the specified labels are added to the selection; when append is False, all original selections are cleared and only the specified labels stay selected.Slicer.unselectItems(labels) — unselects part of the currently selected items.Slicer.clearFilter() — removes the filter and selects all items.SlicerCacheItem.Selected property becomes read-only and its setter is no longer supported. Use the Slicer.selectItems, Slicer.unselectItems, and Slicer.clearFilter methods instead of setting SlicerCacheItem.Selected item by item.
The following code snippet loads the sample Excel file that contains a slicer connected to a pivot table. It selects only the “Blue” and “Pink” items of the slicer with Slicer.selectItems(labels, False) — the pivot table is recalculated directly from the filter items, without a manual Slicer.refresh() call. 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, the pivot table shows only the filtered items.
Replace the current selection (only the specified labels stay selected) and recalculate the linked pivot table or table:
import jpype
import asposecells
jpype.startJVM()
from asposecells.api import Workbook
# Load sample Excel file containing slicer.
workbook = Workbook("sampleUpdatingSlicer.xlsx")
# Access first worksheet.
worksheet = workbook.getWorksheets().get(0)
# Access the first slicer inside the slicer collection.
slicer = worksheet.getSlicers().get(0)
# Select only "Blue" and "Pink"; the linked pivot table or table
# is recalculated directly from the filter items.
slicer.selectItems(["Blue", "Pink"], False)
# Save the modified workbook.
workbook.save("out.xlsx")
jpype.shutdownJVM()
Keep the currently selected labels and additionally select more items:
# Keep the current selection and add "Red" to it.
slicer.selectItems(["Red"], True)
Unselect part of the selected items:
# Remove "Pink" from the current selection.
slicer.unselectItems(["Pink"])
Remove the filter (select all items):
# Clear the filter; all slicer items become selected again.
slicer.clearFilter()
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.