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.
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.
-
1Install IronXL with NuGet Package Manager
-
2Copy and run this code snippet.
IronXL.WorkBook.Create().DefaultWorkSheet["B2"].First().AddComment("Quick tip!", "Dev");C# -
3Deploy to test on your live environment
Start using IronXL in your project today with a free trial
Minimal Workflow (5 steps)
- Download the C# library to enable comment functionality
- Open an existing or create a new Excel spreadsheet
- Use the
AddCommentmethod to add comments - Retrieve and edit comments by accessing the Comment property
- Remove comments from cells using the
RemoveCommentmethod
Get started with IronXL
Start using IronXL in your project today with a free trial.
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 to understand the basics of working with Excel files programmatically. For enterprise applications requiring cloud deployment, IronXL seamlessly integrates with Azure environments and AWS Lambda functions.
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 from scratch or managing existing worksheets, 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 or convert between different spreadsheet 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.
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")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");Imports IronXL
Imports System
' Load an existing workbook
Dim workBook As WorkBook = WorkBook.Load("salesData.xlsx")
Dim workSheet As WorkSheet = workBook.DefaultWorkSheet
' Add comments to cells that meet specific criteria
For row As Integer = 2 To 10
Dim cell = workSheet($"D{row}").First()
Dim value = cell.DoubleValue
If value > 1000 Then
' Add performance comment for high values
cell.AddComment($"Excellent performance! Value: {value:C}", "Sales Manager", True)
ElseIf value < 500 Then
' Add improvement comment for low values
cell.AddComment($"Needs attention. Current: {value:C}", "Sales Manager", False)
End If
Next
' Add timestamp comment to track last update
Dim updateCell = workSheet("A1").First()
updateCell.AddComment($"Last updated: {DateTime.Now:yyyy-MM-dd HH:mm}", "System")
workBook.SaveAs("salesDataWithComments.xlsx")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.
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")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.
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")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 can I add a comment to an Excel cell using IronXL?
To add a comment, use the IronXL method 'AddComment()' on any worksheet cell. It allows you to associate notes or annotations directly with cells.
What parameters does the 'AddComment' method require?
The 'AddComment' method accepts 'content' (string), 'author' (string), and 'isVisible' (boolean) as parameters. All are optional, allowing flexibility in comment creation.
Can I control the visibility of comments by default in IronXL?
Yes, you can set comments to be visible by default with IronXL by specifying 'true' for the 'isVisible' parameter when calling 'AddComment'.
What happens if I add a comment to a cell that already has one?
Using 'AddComment' on a cell that contains an existing comment will replace the old comment with the new one, ensuring no duplicates occur.
How can I edit existing comments in an Excel file using IronXL?
To edit a comment, access the cell's 'Comment' property in IronXL, modify the 'Author', 'Content', or 'IsVisible' properties, then save the workbook.
What happens to the formatting of a cell when a comment is removed?
Removing a comment from a cell in IronXL does not impact the cell’s value, formula, or formatting, ensuring your spreadsheets remain intact.
Is it possible to remove multiple comments from a worksheet in IronXL?
While there's no single method to remove all comments, you can loop through cells programmatically to selectively remove them based on desired criteria.
Why might the 'Comment' property return null in IronXL?
The 'Comment' property returns null if a cell does not have an associated comment, which is common when iterating through cells without comments.
How do I make changes to comment visibility after creation in IronXL?
Access the cell's 'Comment' object and adjust the 'IsVisible' property to 'true' or 'false' as needed to modify comment visibility programmatically.
What types of applications can benefit from using IronXL's comment functionality?
IronXL’s comment functionality is beneficial for ASP.NET web applications and desktop solutions that require annotated, professional, and well-documented Excel files.

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.