Change Slicer Properties

Possible Usage Scenarios

There might be situations where you may want to change the properties of the Slicer such as placement or row height. Aspose.Cells for Python via .NET provides you with the option to update these properties.

How to Change Slicer Properties Using Aspose.Cells for Python Excel Library

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 and changes its properties like row height, width, is printable, title, etc. It saves the workbook as outputChangeSlicerProperties.xlsx.

Sample Code

from aspose.cells import SaveFormat, Workbook
from aspose.cells.drawing import PlacementType
# 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(sourceDir + "sampleCreateSlicerToExcelTable.xlsx")
# Access first worksheet.
worksheet = workbook.worksheets[0]
# Access first table inside the worksheet.
table = worksheet.list_objects[0]
# Add slicer
idx = worksheet.slicers.add(table, 0, "H5")
slicer = worksheet.slicers[idx]
slicer.placement = PlacementType.FREE_FLOATING
slicer.row_height_pixel = 50
slicer.width_pixel = 500
slicer.title = "Aspose"
slicer.alternative_text = "Alternate Text"
slicer.is_printable = False
slicer.is_locked = False
# Refresh the slicer.
slicer.refresh()
# Save the workbook in output XLSX format.
workbook.save(outputDir + "outputChangeSlicerProperties.xlsx", SaveFormat.XLSX)