Inserisci un immagine basata sul riferimento della cella

Inserimento di un’immagine basata sul riferimento della cella

Aspose.Cells for Python via .NET supporta la visualizzazione del contenuto di una cella del foglio di lavoro in una forma immagine. È possibile collegare l’immagine alla cella che contiene i dati che si vogliono visualizzare. Poiché la cella o l’intervallo di celle è collegato all’oggetto grafico, le modifiche apportate ai dati in quella cella o intervallo di celle appaiono automaticamente nell’oggetto grafico. Aggiungi un’immagine al foglio di lavoro chiamando il metodo add_picture della collezione ShapeCollection (incapsulato nell’oggetto Worksheet). Specifica l’intervallo di celle usando l’attributo formula dell’oggetto Picture.

Esempio di codice

from aspose import pycore
from aspose.cells import ConditionalFormattingIcon, IconSetType, Workbook
from aspose.cells.drawing import Picture
from io import BytesIO
# 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(".")
# Instantiate a new Workbook
workbook = Workbook()
# Get the first worksheet's cells collection
cells = workbook.worksheets[0].cells
# Add string values to the cells
cells.get("A1").put_value("A1")
cells.get("C10").put_value("C10")
# 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 a blank picture to the D1 cell
pic = pycore.cast(Picture, workbook.worksheets[0].shapes.add_picture(0, 3, stream, 10, 10))
# Specify the formula that refers to the source range of cells
pic.formula = "A1:C10"
# Update the shapes selected value in the worksheet
workbook.worksheets[0].shapes.update_selected_value()
# Save the Excel file.
workbook.save(dataDir + "referencedpicture.out.xlsx")