如何添加评论

This article was translated from English: Does it need improvement?
Translated
View the article in English

查克尼特·宾

在Excel中,注释是可以添加到单元格中的注释或备注,用以提供额外信息,而不影响单元格的实际内容。 注释对于提供有关特定单元格内数据或计算的解释、背景或提醒很有用。


开始使用IronXL

立即在您的项目中开始使用IronXL,并享受免费试用。

第一步:
green arrow pointer


添加评论示例

选择单元格并使用 AddComment 方法向单元格添加注释。 默认情况下,评论将是不可见的。 将鼠标悬停在单元格上以查看不可见的注释。

:path=/static-assets/excel/content-code-examples/how-to/add-comment-add-comment.cs
using IronXL;
using System.Linq;

WorkBook workBook = WorkBook.Create();
WorkSheet workSheet = workBook.DefaultWorkSheet;

Cell cellA1 = workSheet["A1"].First();
Cell cellD1 = workSheet["D1"].First();

// Add comments
cellA1.AddComment("Hello World!", "John Doe"); // Add comment with content and author. The comment is invisible by default.
cellD1.AddComment(null, null, true); // Add comment with no content and no author. The comment is set to be visible.

workBook.SaveAs("addComment.xlsx");
Imports IronXL
Imports System.Linq

Private workBook As WorkBook = WorkBook.Create()
Private workSheet As WorkSheet = workBook.DefaultWorkSheet

Private cellA1 As Cell = workSheet("A1").First()
Private cellD1 As Cell = workSheet("D1").First()

' Add comments
cellA1.AddComment("Hello World!", "John Doe") ' Add comment with content and author. The comment is invisible by default.
cellD1.AddComment(Nothing, Nothing, True) ' Add comment with no content and no author. The comment is set to be visible.

workBook.SaveAs("addComment.xlsx")
VB   C#

编辑评论示例

访问单元格的评论属性以检索该单元格的评论对象。 这是您可以用来更改作者、内容和可见性的对象。

:path=/static-assets/excel/content-code-examples/how-to/add-comment-edit-comment.cs
using IronXL;
using System.Linq;

WorkBook workBook = WorkBook.Load("addComment.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

Cell cellA1 = workSheet["A1"].First();

// Retrieve comment
var comment = cellA1.Comment;

// Edit comment
comment.Author = "Jane Doe";
comment.Content = "Bye World";
comment.IsVisible = true;

workBook.SaveAs("editComment.xlsx");
Imports IronXL
Imports System.Linq

Private workBook As WorkBook = WorkBook.Load("addComment.xlsx")
Private workSheet As WorkSheet = workBook.DefaultWorkSheet

Private cellA1 As Cell = workSheet("A1").First()

' Retrieve comment
Private comment = cellA1.Comment

' Edit comment
comment.Author = "Jane Doe"
comment.Content = "Bye World"
comment.IsVisible = True

workBook.SaveAs("editComment.xlsx")
VB   C#

删除注释示例

首先访问单元格对象以删除单元格中的注释。 然后,在单元格上调用 RemoveComment 方法。

:path=/static-assets/excel/content-code-examples/how-to/add-comment-remove-comment.cs
using IronXL;
using System.Linq;

WorkBook workBook = WorkBook.Load("addComment.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

Cell cellA1 = workSheet["A1"].First();

// Remove comment
cellA1.RemoveComment();

workBook.SaveAs("removeComment.xlsx");
Imports IronXL
Imports System.Linq

Private workBook As WorkBook = WorkBook.Load("addComment.xlsx")
Private workSheet As WorkSheet = workBook.DefaultWorkSheet

Private cellA1 As Cell = workSheet("A1").First()

' Remove comment
cellA1.RemoveComment()

workBook.SaveAs("removeComment.xlsx")
VB   C#
Chaknith related to 删除注释示例

查克尼特·宾

软件工程师

Chaknith 是开发者中的福尔摩斯。他第一次意识到自己可能在软件工程方面有前途,是在他出于乐趣做代码挑战的时候。他的重点是 IronXL 和 IronBarcode,但他为能帮助客户解决每一款产品的问题而感到自豪。Chaknith 利用他从直接与客户交谈中获得的知识,帮助进一步改进产品。他的轶事反馈不仅仅局限于 Jira 票据,还支持产品开发、文档编写和市场营销,从而提升客户的整体体验。当他不在办公室时,他可能会在学习机器学习、编程或徒步旅行。