Aggiornamento affettatrice
Contents
[
Hide
]
Aggiornamento affettatrice
Aspose.Cells for Python via Java supporta l’aggiornamento delle affettatrici. Per questo, API fornisce la proprietà Slicer.SlicerCache.SlicerCacheItems che viene utilizzata per selezionare o deselezionare gli elementi slicer. Il seguente frammento di codice carica il fileesempio di file Excelche contiene un’affettatrice. Deseleziona il 2° e il 3° elemento dell’affettatrice e aggiorna l’affettatrice usando il metodo Slicer.refresh(). Quindi salva la cartella di lavoro come filefile Excel di output. Lo screenshot seguente mostra l’effetto del codice di esempio sul file Excel di esempio. Come puoi vedere nello screenshot, l’aggiornamento dell’affettatrice con gli elementi selezionati ha aggiornato anche la tabella pivot di conseguenza.
Codice d’esempio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jpype | |
import asposecells | |
jpype.startJVM() | |
from asposecells.api import Workbook, SaveFormat | |
# Load Source Excel file | |
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) | |
# Access the slicer items | |
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 | |
workbook.save("outputUpdatingSlicer.xlsx", SaveFormat.XLSX) | |
jpype.shutdownJVM() |