How to Add Comment in Excel with C# (without Interop)

Add comments to Excel cells in C# using IronXL's simple API—no interop required. Just call AddComment() on any cell to add notes, annotations, or explanations that won't affect your cell data.

Quickstart: Add a Comment to a Cell in One Simple Line

Add a comment to any Excel cell with a single method call. No interop, no complexity—just call AddComment on a cell and you're done.

```cs:title=Add an Excel Comment in One Line with IronXL IronXL.WorkBook.Create().DefaultWorkSheet["B2"].First().AddComment("Quick tip!", "Dev");


<div class="hsg-featured-snippet">
    <h3>Minimal Workflow (5 steps)</h3>
    <ol>
        <li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://nuget.org/packages/IronXL.Excel/">Download the C# library to enable comment functionality</a></li>
        <li>Open an existing or create a new Excel spreadsheet</li>
        <li>Use the <code>AddComment</code> method to add comments</li>
        <li>Retrieve and edit comments by accessing the <strong>Comment</strong> property</li>
        <li>Remove comments from cells using the <code>RemoveComment</code> method</li>
    </ol>
</div>
<br class="clear">

## How Do I Add Comments to Excel Cells?

### What Parameters Does AddComment Accept?

Select the cell and use the `AddComment` method to add a comment to the cell. By default, the comment will be invisible. Hover over the cell to see the comment. The AddComment method accepts three parameters: content (string), author (string), and isVisible (boolean). Both content and author parameters are optional and can be null, allowing you to create empty comments or comments without author attribution.

When working with Excel comments in your .NET applications, understanding how IronXL handles cell referencing is essential. If you're new to IronXL, check out the comprehensive [getting started overview](https://ironsoftware.com/csharp/excel/docs/) to understand the basics of working with Excel files programmatically. For enterprise applications requiring cloud deployment, IronXL seamlessly integrates with [Azure environments](https://ironsoftware.com/csharp/excel/get-started/azure/) and [AWS Lambda functions](https://ironsoftware.com/csharp/excel/get-started/aws/).

### When Should I Make Comments Visible by Default?

Comments are typically hidden by default in Excel to maintain a clean spreadsheet appearance. However, you might want visible comments in scenarios like creating training materials, providing detailed instructions for data entry, or highlighting critical information that users must see immediately. Set the third parameter of AddComment to true to make comments visible without hovering.

For more advanced Excel manipulation tasks, including [creating new spreadsheets](https://ironsoftware.com/csharp/excel/how-to/create-spreadsheet/) from scratch or [managing existing worksheets](https://ironsoftware.com/csharp/excel/how-to/manage-worksheet/), IronXL provides a comprehensive set of tools that work seamlessly together. When building data-driven applications, you might also need to [export Excel data to various formats](https://ironsoftware.com/csharp/excel/how-to/c-sharp-export-to-excel/) or [convert between different spreadsheet types](https://ironsoftware.com/csharp/excel/how-to/convert-spreadsheet-file-types/).

### What Happens If I Add a Comment to a Cell That Already Has One?

When you call AddComment on a cell that already contains a comment, IronXL will replace the existing comment with the new one. This behavior ensures you don't accidentally create duplicate comments on a single cell. If you need to preserve existing comment content, first retrieve it using the Comment property, then concatenate or merge the content before adding the updated comment.

```csharp
:path=/static-assets/excel/content-code-examples/how-to/add-comment-add-comment.cs

Here's a practical example of adding comments to multiple cells in a loop, useful for adding batch annotations or validation notes:

using IronXL;
using System;

// Load an existing workbook
WorkBook workBook = WorkBook.Load("salesData.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Add comments to cells that meet specific criteria
for (int row = 2; row <= 10; row++)
{
    var cell = workSheet[$"D{row}"].First();
    var value = cell.DoubleValue;

    if (value > 1000)
    {
        // Add performance comment for high values
        cell.AddComment($"Excellent performance! Value: {value:C}", "Sales Manager", true);
    }
    else if (value < 500)
    {
        // Add improvement comment for low values
        cell.AddComment($"Needs attention. Current: {value:C}", "Sales Manager", false);
    }
}

// Add timestamp comment to track last update
var updateCell = workSheet["A1"].First();
updateCell.AddComment($"Last updated: {DateTime.Now:yyyy-MM-dd HH:mm}", "System");

workBook.SaveAs("salesDataWithComments.xlsx");
using IronXL;
using System;

// Load an existing workbook
WorkBook workBook = WorkBook.Load("salesData.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Add comments to cells that meet specific criteria
for (int row = 2; row <= 10; row++)
{
    var cell = workSheet[$"D{row}"].First();
    var value = cell.DoubleValue;

    if (value > 1000)
    {
        // Add performance comment for high values
        cell.AddComment($"Excellent performance! Value: {value:C}", "Sales Manager", true);
    }
    else if (value < 500)
    {
        // Add improvement comment for low values
        cell.AddComment($"Needs attention. Current: {value:C}", "Sales Manager", false);
    }
}

// Add timestamp comment to track last update
var updateCell = workSheet["A1"].First();
updateCell.AddComment($"Last updated: {DateTime.Now:yyyy-MM-dd HH:mm}", "System");

workBook.SaveAs("salesDataWithComments.xlsx");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

How Can I Edit Existing Comments?

Why Does the Comment Property Return Null Sometimes?

The Comment property returns null when the selected cell doesn't have an associated comment. This is a common scenario when iterating through cells programmatically. Always check for null before attempting to modify comment properties to avoid NullReferenceException. This pattern is similar to other cell properties in IronXL's comprehensive API.

If you're working with complex Excel files and encountering unexpected null values, the troubleshooting guides can help you understand IronXL's behavior with different Excel formats and file structures. For performance-critical applications processing large Excel files, refer to the performance milestones documentation to optimize your comment operations.

What Properties Can I Modify on a Comment?

IronXL's Comment object exposes three main properties you can modify: Author (string), Content (string), and IsVisible (boolean). The Author property identifies who created the comment, useful for collaborative documents. Content holds the actual comment text, supporting multi-line strings for detailed annotations. IsVisible controls whether the comment displays permanently or only on hover.

These comment properties work alongside other cell formatting features. For instance, you might want to combine comments with cell styling and borders to create visually distinct annotated sections in your spreadsheet. You can also apply conditional formatting to cells with comments to make them stand out visually.

How Do I Change Comment Visibility After Creation?

Retrieve the Comment object by accessing the cell's Comment property. Set the IsVisible property to true or false based on your requirements. This dynamic control allows you to show or hide comments based on user actions or specific conditions in your application logic.

: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

When editing Excel files programmatically, comments provide a non-invasive way to add metadata or notes without altering the actual cell values. This makes them perfect for audit trails, review processes, or providing context for data changes. For applications that need to maintain data integrity, consider protecting your Excel files with passwords while still allowing comment modifications.


How Do I Remove Comments from Cells?

What Happens to Cell Formatting When I Remove a Comment?

Removing a comment from a cell doesn't affect any other cell properties or formatting. The cell's value, formula, style, borders, and background colors remain unchanged. This isolation ensures that comment management operations are safe and won't inadvertently modify your carefully formatted spreadsheets. This behavior aligns with IronXL's principle of preserving workbook metadata and formatting unless explicitly modified.

Can I Remove Multiple Comments at Once?

While IronXL doesn't provide a built-in method to remove all comments from a worksheet simultaneously, you can easily implement this functionality by iterating through cells. Create a simple loop that checks each cell for comments and removes them. This approach gives you fine-grained control, allowing you to selectively remove comments based on criteria like author, content keywords, or cell location.

Remove a comment from a cell by accessing the cell object and calling the RemoveComment method. This operation is immediate and doesn't require saving the workbook to take effect, though you should save your changes to persist them to disk.

: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

Comments in Excel serve various purposes beyond simple annotations. They're valuable for code documentation when generating reports programmatically, providing instructions for data entry forms, or adding revision notes during collaborative editing. When working with data validation, comments can provide helpful hints about acceptable values. For complex data processing workflows, you might combine comments with named ranges to create self-documenting spreadsheets that are easier to maintain.

With IronXL's straightforward API, managing these comments becomes as simple as any other cell operation, making it an essential tool for creating professional, well-documented Excel files in your C# applications. Whether you're building ASP.NET web applications or desktop solutions, IronXL's comment functionality integrates seamlessly into your workflow without the complexity of COM Interop.

Frequently Asked Questions

How do I add a comment to an Excel cell in C#?

You can add comments to Excel cells using IronXL's AddComment method. Simply select a cell and call AddComment with the content, author, and visibility parameters. For example: worksheet["B2"].First().AddComment("Your comment", "Author", false). This requires no interop and works with a single method call.

What parameters does the AddComment method accept?

IronXL's AddComment method accepts three parameters: content (string), author (string), and isVisible (boolean). Both content and author parameters are optional and can be null, allowing you to create empty comments or comments without author attribution. The isVisible parameter controls whether the comment appears without hovering.

Can I create Excel comments without using Office Interop?

Yes, IronXL allows you to add, edit, and remove Excel comments without requiring Office Interop. This makes it ideal for server environments and cloud deployments where Office installation isn't available. The library provides a simple API that handles all Excel comment operations programmatically.

How do I make Excel comments visible by default?

To make comments visible by default in IronXL, set the third parameter of the AddComment method to true. For example: cell.AddComment("Content", "Author", true). This is useful for training materials, data entry instructions, or highlighting critical information that users must see immediately.

Can I retrieve and edit existing comments in Excel cells?

Yes, IronXL allows you to retrieve existing comments by accessing the Comment property of a cell. Once retrieved, you can modify the comment's content, author, or visibility settings. This enables dynamic comment management in your Excel automation workflows.

How do I remove comments from Excel cells programmatically?

IronXL provides the RemoveComment method to delete comments from cells. Simply call this method on any cell that contains a comment to remove it. This is useful for cleaning up spreadsheets or updating comment information programmatically.

What's the minimal code needed to add a comment to Excel?

The minimal code to add a comment using IronXL is just one line: IronXL.WorkBook.Create().DefaultWorkSheet["B2"].First().AddComment("Quick tip!", "Dev"). This creates a workbook, selects cell B2, and adds a comment with content and author—no additional setup required.

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.
Ready to Get Started?
Nuget Downloads 1,753,501 | Version: 2025.12 just released