We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Syncfusion Feedback


Trusted by the world’s leading companies

Overview

The Syncfusion .NET Excel (XlsIO) library offers comprehensive support for threaded comments, providing a structured and organized method for attaching, managing, and organizing annotations, and discussions directly associated with specific cells.


How to add threaded comments to Excel using C#

Here is an example of how to add threaded comments in Excel using C#.

using (ExcelEngine excelEngine = new ExcelEngine())
{
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Xlsx;
    using (FileStream inputStream = new FileStream("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);
 
        //Saving the workbook as a stream
        using (FileStream outputstream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite))
        {
            workbook.SaveAs(outputstream);
        }
    }
}

How to add a reply to a threaded comment in C#

Replies can be added to existing threaded comments using AddReply() method.

Here is an example of how to add a reply to a threaded comment in Excel using C#.

using (ExcelEngine excelEngine = new ExcelEngine())
{
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Xlsx;
 
    using (FileStream inputStream = new FileStream("CommentsTemplate.xlsx", FileMode.Open, FileAccess.Read))
    {
        IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic);
        IWorksheet worksheet = workbook.Worksheets[0];
 
        // Add replies to the threaded comment
        worksheet.Range["H16"].ThreadedComment.AddReply("The unit cost of the desk is higher compared to other items in the west region. As a result, the total amount is elevated.", "User2", DateTime.Now);
        worksheet.Range["H16"].ThreadedComment.AddReply("Additionally, Wilson sold 31 desks in the west region, which is also a contributing factor to the increased total amount.", "User3", DateTime.Now);
 
        // Saving the workbook as a stream
        using (FileStream outputstream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite))
        {   
          workbook.SaveAs(outputstream);
        }
    }
}

How to mark threaded comments as resolved in Excel using C#

Threaded comments can be marked as resolved using IsResolved of IThreadedComment.

Here is an example of how to resolve a threaded comment in Excel using C#.

using (ExcelEngine excelEngine = new ExcelEngine())
{
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Xlsx;
 
    using (FileStream inputStream = new FileStream("CommentsTemplate.xlsx", FileMode.Open, FileAccess.Read))
    {
        IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic);
        IWorksheet worksheet = workbook.Worksheets[0];
 
        //Get the threaded comment in the worksheet
        IThreadedComment threadedComment = worksheet.ThreadedComments[0];
 
        // Resolve the thread
        threadedComment.IsResolved = true;
 
        // Saving the workbook as a stream
        using (FileStream outputstream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite))
        {
           workbook.SaveAs(outputstream);
        }
    }
}

How to delete a threaded comment in C#

Replies of the threaded comments can be deleted using Replies of IThreadedComment.Threaded comment for a cell can be deleted using Delete() method.

Here is an example of how to delete a threaded comment in Excel using C#.

using (ExcelEngine excelEngine = new ExcelEngine())
{
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Xlsx;
 
    using (FileStream inputStream = new FileStream(@"D:\Customer Bugs\Samples\ConsoleApp1\ConsoleApp1\Data\CommentsTemplate.xlsx", FileMode.Open, FileAccess.Read))
    {
        IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic);
        IWorksheet worksheet = workbook.Worksheets[0];
 
        //Get the threaded comment in the worksheet
        IThreadedComment threadedComment = worksheet.ThreadedComments[0];
 
        //Delete the reply to the threaded comment
        threadedComment.Replies[0].Delete();
 
        //Delete the threaded comment
        threadedComment.Delete();
 
        // Saving the workbook as a stream
        using (FileStream outputstream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite))
        {
            workbook.SaveAs(outputstream);
        }
    }
}

How to clear threaded comments in C#

Threaded comments collections in the worksheet can be removed using the Clear() method.

Here is an example of how to clear threaded comments in Excel using C#.

using (ExcelEngine excelEngine = new ExcelEngine())
{
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Xlsx;
    using (FileStream inputStream = new FileStream("CommentsTemplate.xlsx", FileMode.Open, FileAccess.Read))
    {
        IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic);
        IWorksheet worksheet = workbook.Worksheets[0];
 
        //Get the collection of threaded comments in the worksheet
        IThreadedComments threadedComments = worksheet.ThreadedComments;
 
        //clear all the threaded comments from the collection
        threadedComments.Clear();
 
        //Saving the workbook as a stream
        using (FileStream outputstream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite))
        {
            workbook.SaveAs(outputstream);
        }
    }
}


Awards

Greatness—it’s one thing to say you have it, but it means more when others recognize it. Syncfusion is proud to hold the following industry awards.

Scroll up icon