获取在条件格式中使用的图标集、数据条或颜色刻度对象
Contents
[
Hide
]
有时,您需要获取用于单元格或单元格范围条件格式的图标集,并根据它创建图片文件。你可能需要读取条件格式中使用的数据条或颜色刻度。Aspose.Cells for Python via .NET 支持这一功能。
以下代码示例显示了如何读取用于条件格式的图标集。借助 Aspose.Cell 的简单 API,图标集的图像数据将保存为图像。
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 Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Open a template Excel file | |
workbook = Workbook(dataDir + "book1.xlsx") | |
# Get the first worksheet in the workbook | |
sheet = workbook.worksheets[0] | |
# Get the A1 cell | |
cell = sheet.cells.get("A1") | |
# Get the conditional formatting result object | |
cfr = cell.get_conditional_formatting_result() | |
# Get the icon set | |
icon = cfr.conditional_formatting_icon | |
# Create the image file based on the icon's image data | |
with open(dataDir + "imgIcon.out.jpg", "wb") as f: | |
f.write(icon.image_data) |