How to change background in comment in Excel

How to change color in comment in Excel

When you don’t need the default background color for comments, you may want to replace it with a color you’re interested in.How do I change the background color of the Comments box in Excel?

The following code will guide you how to use Aspose.Cells for Python via .NET to add your favorite background color to comments of your own choice.

Here we have prepared a sample file for you.This file is used to initialize the Workbook object in the code below.

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")

Execute the above code and you will get an output file.

How to insert picture or image in comment in Excel

Microsoft Excel lets users customize the look and feel of spreadsheets to a great extent. It is even possible to add background pictures to comments.Adding a background image can be an aesthetic choice, or be used to strengthen branding.

The sample code below creates an XLSX file from scratch using Aspose.Cells for Python via .NET API , and adds a comment with a picture background to cell 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)