管理工作表中的评论

添加评论

要使用 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.");

注释收集在工作表对象提供重载添加方法。开发人员可以使用任何重载版本添加方法根据自己的具体需要。

访问评论

要访问和修改工作表中的现有评论,开发人员可以从注释的集合工作表通过指定插入注释的单元格(使用单元格名称或其在行号和列号方面的位置)。访问评论后,开发人员可以在运行时修改其文本。

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

删除评论

要删除现有评论,开发人员只需访问所需的工作表,然后去掉来自的评论注释的集合工作表通过指定包含注释的单元格(使用其名称或行号和列号)。

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