Agregar un conjunto de iconos condicionales con el texto de la celda

Contents
[ ]

La siguiente muestra de código muestra cómo agregar un conjunto de iconos condicionales con el texto de la celda.

from aspose.cells import ConditionalFormattingIcon, IconSetType, Workbook
from io import BytesIO
from os import os, path
# 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(".")
# Create directory if it is not already present.
IsExists = path.isdir(dataDir)
if notIsExists:
os.makedirs(dataDir)
# Instantiate a new Workbook
workbook = Workbook()
# Get the first worksheet (default worksheet) in the workbook
worksheet = workbook.worksheets[0]
# Get the cells
cells = worksheet.cells
# Set the columns widths (A, B and C)
worksheet.cells.set_column_width(0, 24)
worksheet.cells.set_column_width(1, 24)
worksheet.cells.set_column_width(2, 24)
# Input date into the cells
cells.get("A1").put_value("KPIs")
cells.get("A2").put_value("Total Turnover (Sales at List)")
cells.get("A3").put_value("Total Gross Margin %")
cells.get("A4").put_value("Total Net Margin %")
cells.get("B1").put_value("UA Contract Size Group 4")
cells.get("B2").put_value(19551794)
cells.get("B3").put_value(11.8070745566204)
cells.get("B4").put_value(11.858589818569)
cells.get("C1").put_value("UA Contract Size Group 3")
cells.get("C2").put_value(8150131.66666667)
cells.get("C3").put_value(10.3168384396244)
cells.get("C4").put_value(11.3326931937091)
# Get the conditional icon's image data
imagedata = ConditionalFormattingIcon.get_icon_image_data(IconSetType.TRAFFIC_LIGHTS31, 0)
# Create a stream based on the image data
stream = BytesIO(imagedata)
# Add the picture to the cell based on the stream
worksheet.pictures.add(1, 1, stream)
# Get the conditional icon's image data
imagedata1 = ConditionalFormattingIcon.get_icon_image_data(IconSetType.ARROWS3, 2)
# Create a stream based on the image data
stream1 = BytesIO(imagedata1)
# Add the picture to the cell based on the stream
worksheet.pictures.add(1, 2, stream1)
# Get the conditional icon's image data
imagedata2 = ConditionalFormattingIcon.get_icon_image_data(IconSetType.SYMBOLS3, 0)
# Create a stream based on the image data
stream2 = BytesIO(imagedata2)
# Add the picture to the cell based on the stream
worksheet.pictures.add(2, 1, stream2)
# Get the conditional icon's image data
imagedata3 = ConditionalFormattingIcon.get_icon_image_data(IconSetType.STARS3, 0)
# Create a stream based on the image data
stream3 = BytesIO(imagedata3)
# Add the picture to the cell based on the stream
worksheet.pictures.add(2, 2, stream3)
# Get the conditional icon's image data
imagedata4 = ConditionalFormattingIcon.get_icon_image_data(IconSetType.BOXES5, 1)
# Create a stream based on the image data
stream4 = BytesIO(imagedata4)
# Add the picture to the cell based on the stream
worksheet.pictures.add(3, 1, stream4)
# Get the conditional icon's image data
imagedata5 = ConditionalFormattingIcon.get_icon_image_data(IconSetType.FLAGS3, 1)
# Create a stream based on the image data
stream5 = BytesIO(imagedata5)
# Add the picture to the cell based on the stream
worksheet.pictures.add(3, 2, stream5)
dataDir = dataDir + "outfile_cond_icons1.out.xlsx"
# Save the Excel file
workbook.save(dataDir)