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.


Get started with IronXL

Start using IronXL in your project today with a free trial.

First Step:
green arrow pointer


Add 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 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")
$vbLabelText   $csharpLabel

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")
$vbLabelText   $csharpLabel

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")
$vbLabelText   $csharpLabel

Frequently Asked Questions

How can I add a comment to an Excel cell using C#?

You can add a comment to an Excel cell using the IronXL library in C#. First, download the library from NuGet. Then, use the AddComment method on the cell object to insert a comment.

How do I edit an existing comment in an Excel spreadsheet?

To edit an existing comment in an Excel spreadsheet using IronXL, access the Comment property of the cell. This allows you to change the content, author, and visibility of the comment.

What is the process to remove a comment from a cell in Excel?

To remove a comment from a cell in Excel using IronXL, access the cell object and call the RemoveComment method on it.

How do I save an Excel workbook after making changes to comments?

After adding or editing comments in an Excel workbook using IronXL, ensure you save the changes by calling the Save method on the WorkBook object.

Can comments in Excel be invisible by default?

Yes, comments in Excel are invisible by default when added using IronXL. They become visible when you hover over the cell.

What do I need to enable comment functionality in Excel using C#?

To enable comment functionality in Excel using C#, download and install the IronXL.Excel library from NuGet.

Can the author of a comment be updated in Excel?

Yes, you can update the author of a comment in Excel by accessing the Comment object of the cell and setting the Author property using IronXL.

How can I verify if a cell contains a comment?

You can verify if a cell contains a comment by using the HasComment property of the cell with IronXL.

Which programming language is used for adding comments to Excel sheets?

C# is the programming language used with IronXL for adding comments to Excel sheets.

Is it possible to annotate Excel spreadsheets without using Interop?

Yes, you can annotate Excel spreadsheets without using Interop by utilizing IronXL's library to add, edit, and remove comments.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.