格式化切片器

可能的使用场景

您可以通过设置其列数或样式等方式来设置 Microsoft Excel 中的数据透视表筛选器的格式。Aspose.Cells for Python via .NET 也允许您使用 Slicer.number_of_columnsSlicer.style_type 属性来实现此功能。

如何使用 Aspose.Cells for Python Excel 库格式化数据透视表筛选器

请参阅以下代码,它加载了包含切片器的sample Excel file。它访问该切片器并设置其列数和样式类型,然后将其保存为output Excel file。截图展示了在执行示例代码后切片器的外观。

todo:image_alt_text

示例代码

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)