管理工作表中的评论
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."); |
注释收集在工作表对象提供重载添加方法。开发人员可以使用任何重载版本添加方法根据自己的具体需要。
访问评论
要访问和修改工作表中的现有评论,开发人员可以从注释的集合工作表通过指定插入注释的单元格(使用单元格名称或其在行号和列号方面的位置)。访问评论后,开发人员可以在运行时修改其文本。
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."); | |
} |
删除评论
要删除现有评论,开发人员只需访问所需的工作表,然后去掉来自的评论注释的集合工作表通过指定包含注释的单元格(使用其名称或行号和列号)。
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."); | |
} |