Create Slicer to Excel Table

Possible Usage Scenarios

A slicer is used to filter data quickly. It can be used to filter data both in a table or pivot table. Microsoft Excel allows you to create slicer by selecting a table or pivot table and then clicking the Insert > Slicer. Aspose.Cells also allows you to create slicer using the Worksheet.Slicers.Add() method.

Create Slicer to Excel Table

Please see the following sample code. It loads the sample Excel file that contains a table. It then creates the slicer based on the first column. Finally, it saves the workbook in output XLSX format.

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 a table.
Workbook workbook = new Workbook(sourceDir + "sampleCreateSlicerToExcelTable.xlsx");
// Access first worksheet.
Worksheet worksheet = workbook.getWorksheets().get(0);
// Access first table inside the worksheet.
ListObject table = worksheet.getListObjects().get(0);
// Add slicer
int idx = worksheet.getSlicers().add(table, 0, "H5");
// Save the workbook in output XLSX format.
workbook.save(outputDir + "outputCreateSlicerToExcelTable.xlsx", SaveFormat.XLSX);