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 for Python via .NET also allows you to do this using the Slicer.number_of_columns and Slicer.style_type properties.
How to Format Slicer Using Aspose.Cells for Python Excel Library
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
from aspose.cells import SaveFormat, Workbook | |
from aspose.cells.slicers import SlicerStyleType | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Load sample Excel file containing slicer. | |
wb = Workbook("sampleFormattingSlicer.xlsx") | |
# Access first worksheet. | |
ws = wb.worksheets[0] | |
# Access the first slicer inside the slicer collection. | |
slicer = ws.slicers[0] | |
# Set the number of columns of the slicer. | |
slicer.number_of_columns = 2 | |
# Set the type of slicer style. | |
slicer.style_type = SlicerStyleType.SLICER_STYLE_LIGHT6 | |
# Save the workbook in output XLSX format. | |
wb.save("outputFormattingSlicer.xlsx", SaveFormat.XLSX) |