Inserisci l'affettatrice
Possibili scenari di utilizzo
Un’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 ilWorksheet.Slicers.Add()metodo.
Crea Slicer in una tabella pivot
Vedere il seguente codice di esempio. Carica ilesempio di file Excel che contiene la tabella pivot. Quindi crea l’affettatrice in base al primo campo pivot di base. Infine, salva la cartella di lavoro inuscita XLSX euscita XLSB formato. Lo screenshot seguente mostra l’affettatrice creata da Aspose.Cells nel file Excel di output.
Codice d’esempio
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Load sample Excel file containing pivot table. | |
Workbook wb = new Workbook("sampleCreateSlicerToPivotTable.xlsx"); | |
// Access first worksheet. | |
Worksheet ws = wb.Worksheets[0]; | |
// Access first pivot table inside the worksheet. | |
Aspose.Cells.Pivot.PivotTable pt = ws.PivotTables[0]; | |
// Add slicer relating to pivot table with first base field at cell B22. | |
int idx = ws.Slicers.Add(pt, "B22", pt.BaseFields[0]); | |
// Access the newly added slicer from slicer collection. | |
Aspose.Cells.Slicers.Slicer slicer = ws.Slicers[idx]; | |
// Save the workbook in output XLSX format. | |
wb.Save("outputCreateSlicerToPivotTable.xlsx", SaveFormat.Xlsx); | |
// Save the workbook in output XLSB format. | |
wb.Save("outputCreateSlicerToPivotTable.xlsb", SaveFormat.Xlsb); |
Crea affettatrice in tabella Excel
Vedere il seguente codice di esempio. Carica ilesempio di file Excel che contiene una tabella. Quindi crea l’affettatrice in base alla prima colonna. Infine, salva la cartella di lavoro inuscita XLSX formato.
Codice d’esempio
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Load sample Excel file containing a table. | |
Workbook workbook = new Workbook(sourceDir + "sampleCreateSlicerToExcelTable.xlsx"); | |
// Access first worksheet. | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access first table inside the worksheet. | |
ListObject table = worksheet.ListObjects[0]; | |
// Add slicer | |
int idx = worksheet.Slicers.Add(table, 0, "H5"); | |
// Save the workbook in output XLSX format. | |
workbook.Save(outputDir + "outputCreateSlicerToExcelTable.xlsx", SaveFormat.Xlsx); |