在工作表中管理注释
Contents
[
Hide
]
在MS Excel中,您必须熟悉评论功能,该功能允许用户向单元格添加评论。在需要向用户提供一些信息以供其在单元格中输入值时,此功能非常有用。每当用户将鼠标指针放在评论单元格上时,都会弹出一个小窗口消息,向用户提供一些信息。使用Aspose.Cells.GridDesktop,开发人员可以在单元格上创建评论。在本主题中,我们将详细解释此功能的用法。
添加评论
要使用Aspose.Cells.GridDesktop向单元格添加注释,请按照以下步骤执行:
- 向您的表单中添加Aspose.Cells.GridDesktop控件
- 访问任何所需的工作表
- 通过指定要添加注释的单元格(使用名称或行和列号)向工作表添加注释
下面的代码将向工作表的b2和b4单元格添加评论。
This file contains hidden or 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 | |
// Accessing first worksheet of the Grid | |
Worksheet sheet = gridDesktop1.Worksheets[0]; | |
// Adding comment to "b2" cell | |
sheet.Comments.Add("b2", "Please write your name."); | |
// Adding another comment to "b4" cell using its row & column number | |
sheet.Comments.Add(3, 1, "Please write your email."); |
工作表对象中的Comments集合提供了重载的Add方法。开发人员可以根据其特定需求使用Add方法的任何重载版本。
访问评论
要访问和修改工作表中的现有注释,开发人员可以通过指定要访问的工作表的Comments集合(使用单元格名称或其行和列号的位置)来访问注释。一旦访问了注释,开发人员可以在运行时修改其文本。
This file contains hidden or 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 | |
// Accessing first worksheet of the Grid | |
Worksheet sheet = gridDesktop1.Worksheets[0]; | |
// Accessing a comment added to "c3" cell (specified using its row & column number) | |
Aspose.Cells.GridDesktop.Data.GridComment comment1 = sheet.Comments[3, 1]; | |
if (comment1 != null) | |
{ | |
// Modifying the text of comment | |
comment1.Text = "The 1st comment."; | |
MessageBox.Show("Comment has been modified"); | |
} | |
else | |
{ | |
MessageBox.Show("Please add comment before accessing it."); | |
} |
移除评论
要删除现有的评论,开发人员可以简单地访问所需的工作表,然后通过指定包含评论的单元格(使用其名称或行和列号)在工作表的Comments集合中移除评论。
This file contains hidden or 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 | |
// Accessing first worksheet of the Grid | |
Worksheet sheet = gridDesktop1.Worksheets[0]; | |
if (sheet.Comments[3, 1] != null) | |
{ | |
// Removing comment from "c3" cell | |
sheet.Comments.Remove(3, 1); | |
MessageBox.Show("Comment has been removed"); | |
} | |
else | |
{ | |
MessageBox.Show("Please add comment before removing it."); | |
} |