如何添加评论
This article was translated from English: Does it need improvement?
TranslatedView the article in English
在Excel中,注释是可以添加到单元格中的注释或备注,用以提供额外信息,而不影响单元格的实际内容。 注释对于提供有关特定单元格内数据或计算的解释、背景或提醒很有用。
如何添加评论
- 下载 C# 库以启用注释功能
- 打开现有或新建 Excel 电子表格
- 使用
添加评论
方法添加评论 - 通过访问 评论 属性
- 使用
删除评论
方法
开始使用IronXL
立即在您的项目中开始使用IronXL,并享受免费试用。
添加评论示例
选择单元格并使用 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#