Come cambiare lo sfondo nel commento in Excel

Come cambiare il colore nel commento in Excel

Quando non hai bisogno del colore di sfondo predefinito per i commenti, potresti voler sostituirlo con un colore di tuo interesse. Come cambio il colore di sfondo della casella Commenti in Excel?

Il codice seguente ti guiderà su come utilizzare Aspose.Cells for Python via .NET per aggiungere il tuo colore di sfondo preferito ai commenti da scegliere.

Qui abbiamo preparato un file di esempio (exmaple.xlsx) per te. Questo file viene utilizzato per inizializzare l’oggetto Workbook nel codice sottostante.

from aspose.cells import Workbook
from aspose.pydrawing import Color
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
path = ""
# Initialize a new workbook.
book = Workbook(path + "exmaple.xlsx")
# Accessing the newly added comment
comment = book.worksheets[0].comments[0]
# change background color
shape = comment.comment_shape
shape.fill.solid_fill.color = Color.red
# Save the Excel file
book.save(path + "result.xlsx")

Esegui il codice sopra e otterrai un file di output (result.xlsx).

Come inserire un’immagine o una foto nel commento in Excel

Microsoft Excel consente agli utenti di personalizzare aspetto e sensazione dei fogli di calcolo in gran parte. È persino possibile aggiungere immagini di sfondo ai commenti. Aggiungere un’immagine di sfondo può essere una scelta estetica o essere utilizzata per rafforzare il marchio.

Il codice di esempio qui sotto crea un file XLSX da zero utilizzando l’API Aspose.Cells for Python via .NET e aggiunge un commento con un’immagine di sfondo alla cella A1.

from aspose.cells import SaveFormat, Workbook
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 = ""
# Create directory if it is not already present.
IsExists = path.isdir(dataDir)
if not IsExists:
os.makedirs(dataDir)
# Instantiate a Workbook
workbook = Workbook()
# Get a reference of comments collection with the first sheet
comments = workbook.worksheets[0].comments
# Add a comment to cell A1
commentIndex = comments.add(0, 0)
comment = comments[commentIndex]
comment.note = "First note."
comment.font.name = "Times New Roman"
# Load an image into stream
byte_array = bytearray()
with open(dataDir + "image2.jpg", 'rb') as file:
byte_array = bytearray(file.read())
# Set image data to the shape associated with the comment
comment.comment_shape.fill.image_data = byte_array
dataDir = dataDir + "commentwithpicture1.out.xlsx"
# Save the workbook
workbook.save(dataDir, SaveFormat.XLSX)