如何在Excel中更改评论的背景
Contents
[
Hide
]
评论被添加到单元格中以记录评论,包括公式运行的详细信息、值的来源或审阅人员的问题。当多个人在不同时间讨论或审查同一份文件时,评论起着极其重要的作用。如何区分不同人的评论?是的,我们可以为每个评论设置不同的背景颜色。但是当我们需要处理大量文档和大量评论时,手动操作是一场灾难。幸运的是Aspose.Cells提供了一个允许你在代码中完成这项工作的API。
如何在Excel中更改评论的颜色
当你不需要默认的评论背景颜色时,你可能希望用你感兴趣的颜色来替换它。如何在Excel中更改评论框的背景颜色?
以下代码将指导你如何使用Aspose.Cells为你自己选择的评论添加喜欢的背景颜色。
在这里,我们已为您准备了一个样本文件。这个文件用于在下面的代码中初始化Workbook对象。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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添加具有图片背景的评论。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |