Formatting Slicer
Possible Usage Scenarios
You can format the slicer in Microsoft Excel by setting its number of columns or by setting its style etc. Aspose.Cells also allows you to do this using the Slicer.NumberOfColumns and Slicer.StyleType properties.
Formatting Slicer
Please see the following code, it loads the sample Excel file that contains a slicer. It accesses the slicer and sets its number of columns and style type and saves it as output Excel file. The screenshot shows how the slicer looks after the execution of the sample code.
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 slicer. | |
Workbook wb = new Workbook(srcDir + "sampleFormattingSlicer.xlsx"); | |
// Access first worksheet. | |
Worksheet ws = wb.getWorksheets().get(0); | |
// Access the first slicer inside the slicer collection. | |
Slicer slicer = ws.getSlicers().get(0); | |
// Set the number of columns of the slicer. | |
slicer.setNumberOfColumns(2); | |
// Set the type of slicer style. | |
slicer.setStyleType(SlicerStyleType.SLICER_STYLE_LIGHT_6); | |
// Save the workbook in output XLSX format. | |
wb.save(outDir + "outputFormattingSlicer.xlsx", SaveFormat.XLSX); |