Crea Slicer in una tabella pivot
Contents
[
Hide
]
Possibili scenari di utilizzo
L’affettatrice viene utilizzata per filtrare rapidamente i dati. Può essere utilizzato per filtrare i dati sia in una tabella che in una tabella pivot. Microsoft Excel consente di creare un’affettatrice selezionando una tabella o una tabella pivot e quindi facendo clic sull’iconaInserisci > Affettatrice. Aspose.Cells permette anche di creare affettatrici utilizzando ilFoglio di lavoro.getSlicers().add() metodo.
Crea Slicer in una tabella pivot
Vedere il seguente codice di esempio. Carica ilesempio di file Excelche contiene la tabella pivot. Quindi crea l’affettatrice in base al primo campo pivot di base. Infine, salva la cartella di lavoro inuscita XLSXeuscita XLSBformato. Lo screenshot seguente mostra l’affettatrice creata da Aspose.Cells nel file Excel di output.
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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// Load sample Excel file containing pivot table. | |
Workbook wb = new Workbook(srcDir + "sampleCreateSlicerToPivotTable.xlsx"); | |
// Access first worksheet. | |
Worksheet ws = wb.getWorksheets().get(0); | |
// Access first pivot table inside the worksheet. | |
PivotTable pt = ws.getPivotTables().get(0); | |
// Add slicer relating to pivot table with first base field at cell B22. | |
int idx = ws.getSlicers().add(pt, "B22", pt.getBaseFields().get(0)); | |
// Access the newly added slicer from slicer collection. | |
Slicer slicer = ws.getSlicers().get(idx); | |
// Save the workbook in output XLSX format. | |
wb.save(outDir + "outputCreateSlicerToPivotTable.xlsx", SaveFormat.XLSX); | |
// Save the workbook in output XLSB format. | |
wb.save(outDir + "outputCreateSlicerToPivotTable.xlsb", SaveFormat.XLSB); |