How to Add Comments to Excel Documents Using C#
Detailed Blog page Skeleton loader
How to Add Comments to Excel Documents Using C#

Commenting is a useful feature in Excel documents that allows users to add additional information about specific cell data, calculations, and references used inside a cell. Comments serve as a form of documentation to help you and others understand the content and context of your Excel workbook. They are particularly useful when sharing workbooks with other collaborators.

From the 2023 Volume 3 release on, the Syncfusion Excel Library (XlsIO) supports adding threaded comments to Excel documents. With this feature, you can allow multiple users to add comments or reply to existing comments in an Excel worksheet.

Enjoy a smooth experience with Syncfusion’s Excel Library! Get started with a few lines of code and without Microsoft or interop dependencies.

You can perform the following actions with threaded-comments support in the Excel Library:

Let’s see how to perform these actions with code examples!

Note: If you are new to our Excel Library, following our getting started guide is highly recommended.

Add comment

A comment can be any text related to the cell information. The following code example illustrates how to add threaded comments to a cell in a worksheet.

using (ExcelEngine excelEngine = new ExcelEngine())
{
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Xlsx;

    FileStream inputStream = new FileStream("../../../Data/CommentsTemplate.xlsx", FileMode.Open, FileAccess.Read);
    IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic);

    IWorksheet worksheet = workbook.Worksheets[0];

    //Add threaded comments.
    IThreadedComment threadedComment = worksheet.Range["H16"].AddThreadedComment("What is the reason for the higher total amount of \"desk\"  in the west region?", "User1", DateTime.Now);

    FileStream stream = new FileStream("output.xlsx", FileMode.Create, FileAccess.ReadWrite);
    workbook.SaveAs(stream);
    workbook.Close();
    excelEngine.Dispose();
}

This results in the following image.

Adding a threaded comment in an Excel document
Adding a threaded comment in an Excel document

Syncfusion’s high-performance Excel Library offers a plethora of state-of-the art features backed by comprehensive documentation.

Reply to comment

You can add a reply to an existing comment in an Excel document. The following code example illustrates how to add a reply to a comment using C#

//Add threaded comments.
IThreadedComment threadedComment = worksheet.Range["H16"].AddThreadedComment("What is the reason for the higher total amount of \"desk\"  in the west region?", "User1", DateTime.Now);
                
//Add reply to the threaded comment.
threadedComment.AddReply("The unit cost of desk is higher compared to other items in the west region. As a result, the total amount is elevated.", "User2", DateTime.Now);

Refer to the following image.

Replying to a comment in an Excel document
Replying to a comment in an Excel document

Experience Syncfusion's Excel Framework in action through interactive demos, giving you the confidence to implement it in your projects immediately.

Mark as resolved

You can also mark a discussion (comments) created for a cell as resolved. This way, other users know to ignore the discussion.

The following code example illustrates how to mark a discussion as resolved.

//Add threaded comments.
IThreadedComment threadedComment = worksheet.Range["H16"].AddThreadedComment("What is the reason for the higher total amount of \"desk\"  in the west region?", "User1", DateTime.Now);
                
//Add reply to the threaded comment.
threadedComment.AddReply("The unit cost of desk is higher compared to other items in the west region. As a result, the total amount is elevated.", "User2", DateTime.Now);

//Mark as resolved.
threadedComment.IsResolved = true;

Refer to the following image.

Marking a discussion as resolved in an Excel document
Marking a discussion as resolved in an Excel document

GitHub reference

You can download examples of threaded comments in Excel documents using C# from this GitHub page.

From simple data tables to complex financial models, Syncfusion empowers you to unleash your creativity and design stunning Excel spreadsheets.

Conclusion

Thanks for reading! In this blog, we’ve explored the new threaded comments feature added to the Syncfusion Excel Library (XlsIO) for the 2023 Volume 3  release. This feature is useful for collaborating on Excel documents and getting feedback from others.

Take a moment to peruse the documentation, where you’ll find other Excel options and features like conditional formattingtablespivot tables, and charts.

Using the Excel Library, you can export Excel data to PDFimagedata tableCSVTSVHTMLcollections of objectsODSJSON, and more file formats.

Are you already a Syncfusion user? You can download the product setup here. If you’re not a Syncfusion user yet, you can download a free 30-day trial here.

Please let us know in the comments section below if you have any questions about these features. You can also contact us through our support forumsupport portal, or feedback portal. We are always happy to assist you!

Related blogs

Be the first to get updates

Mohan Chandran

Meet the Author

Mohan Chandran

Mohan Chandran is an employee at Syncfusion Software with 4+ years of experience working in an Excel-related library called XlsIO. He is good at finding solutions and resolving queries related to Excel.