如何在Excel中更改评论的背景

如何在Excel中更改评论的颜色

当你不需要默认的评论背景颜色时,你可能希望用你感兴趣的颜色来替换它。如何在Excel中更改评论框的背景颜色?

以下代码将指导你如何使用Aspose.Cells为你自己选择的评论添加喜欢的背景颜色。

在这里,我们已为您准备了一个样本文件。这个文件用于在下面的代码中初始化Workbook对象。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string path = "";
//Initialize a new workbook.
Workbook book = new Workbook(path + "exmaple.xlsx");
// Accessing the newly added comment
Comment comment = book.Worksheets[0].Comments[0];
// change background color
Shape shape = comment.CommentShape;
shape.Fill.SolidFill.Color = Color.Red;
// Save the Excel file
book.Save(path + "result.xlsx");

执行上述代码,你将得到一个输出文件

如何在Excel中评论中插入图片或图像

微软Excel允许用户在很大程度上自定义电子表格的外观。甚至可以向评论中添加背景图片。添加背景图片可以是一种美学选择,也可以用于加强品牌形象。

下面的示例代码使用Aspose.Cells API从头开始创建一个XLSX文件,并向单元A1添加具有图片背景的评论。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = "";
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiate a Workbook
Workbook workbook = new Workbook();
// Get a reference of comments collection with the first sheet
CommentCollection comments = workbook.Worksheets[0].Comments;
// Add a comment to cell A1
int commentIndex = comments.Add(0, 0);
Comment comment = comments[commentIndex];
comment.Note = "First note.";
comment.Font.Name = "Times New Roman";
// Load an image into stream
Bitmap bmp = new Bitmap(dataDir + "image2.jpg");
MemoryStream ms = new MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
// Set image data to the shape associated with the comment
comment.CommentShape.Fill.ImageData = ms.ToArray();
dataDir = dataDir + "commentwithpicture1.out.xlsx";
// Save the workbook
workbook.Save(dataDir, Aspose.Cells.SaveFormat.Xlsx);