Threaded comments in Excel are an essential feature for collaborative work. It allows multiple users to add, edit, and review conversation threads within a shared document. In certain cases, we may need to manage these threaded comments programmatically. In this blog post, we will learn how to read, add, and edit threaded comments in Excel using C#.
This article covers the following topics:
- C# Excel API for Managing Threaded Comments
- Add Threaded Comments in Excel using C#
- Read Threaded Comments for a Specific Cell in Excel
- Read All Threaded Comments in Excel using C#
- Edit a Threaded Comment in Excel using C#
- Delete Threaded Comments in Excel using C#
- Free Resources
C# Excel API for Managing Threaded Comments
For working with threaded comments in Excel worksheets, we will use Aspose.Cells for .NET API. It is a powerful spreadsheet programming API that enables developers to create, manipulate, and convert Excel files in .NET applications. By leveraging Aspose.Cells for .NET, we can easily add, read, edit, or delete threaded comments in Excel worksheets.
To utilize the API, please either download the DLL or install it from NuGet with the following command:
PM> Install-Package Aspose.Cells
Add a Threaded Comment in Excel using C#
We can easily add threaded comments to an Excel worksheet by following the steps below:
- Create an instance of the Workbook class.
- Access the specific worksheet by its index.
- Add an author to the ThreadedCommentAuthors collection using the Add() method.
- Get the ThreadedCommentAuthor class object for the newly created author by its index.
- Add the threaded comment using the AddThreadedComment() method. It takes the cell name, comment text, and ThreadedCommentAuthor object as arguments.
- Save the Excel file using the Workbook.Save(string) method.
The following code sample shows how to add a threaded comment to an Excel worksheet using C#.
Read Threaded Comments for a Specific Cell in Excel
To read threaded comments from a specified cell in an Excel worksheet, follow these steps:
- Load an existing Excel file using the Workbook class.
- Access the worksheet by its index.
- Get threaded comments for a specific cell using the GetThreadedComments() method. It takes the cell name as an argument.
- Loop through all the threaded comments and read the details.
The following code sample shows how to read threaded comments for the specified column from an Excel worksheet using C#.
Author Name: author@domain.com
Threaded comment Notes:Test Threaded Comment
Read All Threaded Comments in Excel using C#
Similarly, we can read all the threaded comments available in an Excel worksheet by following the steps below:
- Load an existing Excel file using the Workbook class.
- Loop through all the comments and read threaded comments one by one.
The following code sample shows how to read all the threaded comments from an Excel worksheet using C#.
Edit a Threaded Comment in Excel using C#
Please follow the steps below in order to update any of the threaded comments in the Excel:
- Load an existing Excel file using the Workbook class.
- Access the worksheet by its index.
- Get threaded comments for a specific cell using the GetThreadedComments() method. It takes the cell name as an argument.
- Update the comment’s notes property.
- Save the Excel file using the Workbook.Save(string) method.
The following code sample shows how to edit threaded comments in an Excel worksheet using C#.
Delete Threaded Comments in Excel using C#
We can also delete the threaded comments for a specific cell in an Excel worksheet by following the steps below:
- Load an existing Excel file using the Workbook class.
- Access the worksheet by its index.
- Remove a comment from the comments collection using the RemoveAt() method. It takes the cell name as an argument.
- Save the Excel file using the Save(string) method.
The following code sample shows how to delete threaded comments in an Excel worksheet using C#.
Get a Free License
Please get a free temporary license to read, add, and edit threaded comments in Excel without trial restrictions. Visit our ‘Temporary License’ page for easy-to-follow instructions on claiming your free license quickly.
Threaded Comments in Excel – Free Resources
In addition to working with threaded comments in Excel worksheets, you can learn more about creating, manipulating, and converting Excel files. Explore various other features of the Aspose.Cells for .NET using the resources below:
Conclusion
In this article, we have learned how to read, add, edit, and delete threaded comments from Excel worksheets using C#. By leveraging Aspose.Cell for .NET, you can easily manipulate Excel worksheets in your C# applications. In case of any ambiguity, please contact us on our free support forum.