Excel でコメントの背景を変更する方法
Excel でコメントの色を変更する方法
既定のコメントの背景色が必要ない場合、興味のある色に置き換えたいことがあるかもしれません。Excel でコメントボックスの背景色を変更する方法は?
以下のコードは、Aspose.Cells for Python via .NET を使用して自分の選択したコメントに好きな背景色を追加する方法を案内します。
ここでは、サンプルファイル をご用意しています。このファイルは、以下のコードでワークブックオブジェクトを初期化するために使用されます。
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") |
上記のコードを実行すると、出力ファイル が生成されます。
Excel でコメントに画像を挿入する方法
Microsoft Excel はスプレッドシートの見た目や感じを大幅にカスタマイズできます。コメントに背景画像を追加することも可能です。背景画像を追加することは見た目の選択肢であり、またブランディングを強化するためにも使用できます。
以下のサンプルコードは、Aspose.Cells for Python via .NET API を使用して XLSX ファイルをゼロから作成し、画像背景のコメントをセル 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) |