在工作表中管理注释

添加评论

要使用Aspose.Cells.GridDesktop向单元格添加注释,请按照以下步骤执行:

  • 向您的表单中添加Aspose.Cells.GridDesktop控件
  • 访问任何所需的工作表
  • 通过指定要添加注释的单元格(使用名称或行和列号)向工作表添加注释

下面的代码将向工作表的b2b4单元格添加评论。

// 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集合(使用单元格名称或其行和列号的位置)来访问注释。一旦访问了注释,开发人员可以在运行时修改其文本。

// 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集合中移除评论。

// 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.");
}