格式化切片器
Contents
[
Hide
]
可能的使用场景
您可以通过设置其列数或样式等方式来设置 Microsoft Excel 中的数据透视表筛选器的格式。Aspose.Cells for Python via .NET 也允许您使用 Slicer.number_of_columns 和 Slicer.style_type 属性来实现此功能。
如何使用 Aspose.Cells for Python Excel 库格式化数据透视表筛选器
请参阅以下代码,它加载了包含切片器的sample Excel file。它访问该切片器并设置其列数和样式类型,然后将其保存为output Excel file。截图展示了在执行示例代码后切片器的外观。
示例代码
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |