格式化切片器
Contents
[
Hide
]
格式化切片器
使用 Microsoft Excel,您可以通过设置其列数、样式等设置切片器的格式。 Aspose.Cells for Python via Java 提供 Slicer.NumberOfColumns 和 Slicer.StyleType 属性来实现此目的。
以下代码片段加载示例 Excel 文件包含一个切片器。它访问切片器并设置其列数和样式类型并将其另存为输出Excel文件.屏幕截图显示了切片器在执行示例代码后的样子。
示例代码
This file contains 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
import jpype | |
import asposecells | |
jpype.startJVM() | |
from asposecells.api import Workbook, SaveFormat, SlicerStyleType | |
# Load Source Excel file | |
workbook = Workbook("sampleFormattingSlicer.xlsx") | |
# Access first worksheet | |
worksheet = workbook.getWorksheets().get(0) | |
# Access the newly added slicer from slicer collection | |
slicer = worksheet.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 | |
workbook.save("outputFormattingSlicer.xlsx", SaveFormat.XLSX) | |
jpype.shutdownJVM() |