How to add Comment

by Chaknith Bin

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 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")
VB   C#

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")
VB   C#

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")
VB   C#
Chaknith related to Remove Comment Example

Chaknith Bin

Software Engineer

Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.