如何添加评论
在 Excel 中,注释是可以添加到单元格中的注解或注释,在不影响单元格实际内容的情况下提供附加信息。注释可用于对特定单元格中的数据或计算进行解释、说明或提醒。
如何添加评论
- 下载 C# 库以启用注释功能
- 打开现有或新建 Excel 电子表格
- 使用
添加评论
方法添加评论 - 通过访问 评论 属性
- 使用
Remove评论
方法
开始在您的项目中使用IronPDF,并立即获取免费试用。
查看 IronXL 上 Nuget 用于快速安装和部署。它有超过800万次下载,正在使用C#改变Excel。
Install-Package IronXL.Excel
考虑安装 IronXL DLL 直接。下载并手动安装到您的项目或GAC表单中: IronXL.zip
手动安装到你的项目中
下载DLL添加评论示例
选择单元格并使用 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")
编辑评论示例
访问单元格的Comment属性,获取单元格的注释对象。您可以使用该对象更改作者、内容和可见性。
: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")
删除评论示例
首先访问单元格对象,删除单元格中的注释。然后,调用单元格上的 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")