How to add Comment
In Excel, a comment is a note or annotation that can be added to a cell to provide additional information without affecting the actual content of the cell. Comments are useful for providing explanations, context, or reminders about the data or calculations within a specific cell.
How to add Comment
- Download the C# library to enable comment functionality
- Open an existing or create a new Excel spreadsheet
- Use the
AddComment
method to add comments - Retrieve and edit comments by accessing the Comment property
- Remove comments from cells using the
RemoveComment
method
Install with NuGet
Install-Package IronXL.Excel
Download DLL
Manually install into your project
Install with NuGet
Install-Package IronXL.Excel
Download DLL
Manually install into your project
Start using IronPDF in your project today with a free trial.
Check out IronXL on Nuget for quick installation and deployment. With over 8 million downloads, it's transforming Excel with C#.
Install-Package IronXL.Excel
Consider installing the IronXL DLL directly. Download and manually install it for your project or GAC form: IronXL.zip
Manually install into your project
Download DLLAdd Comment Example
Select the cell and use the AddComment
method to add a comment to the cell. By default, the comment will be invisible. Hover on the cell to see the invisible comment.
: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")
Edit Comment Example
Access the Comment property of the cell to retrieve the Comment object for the cell. This is the object you can use to change the Author, Content, and visibility.
: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")
Remove Comment Example
Remove a comment from a cell by first accessing the cell object. Then, call the RemoveComment
method on the cell.
: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")