Skip to main content
All docs
V23.2
Row

Worksheet.ThreadedComments Property

Obtains a collection of threaded comments.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v23.2.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

ThreadedCommentCollection ThreadedComments { get; }

Property Value

Type Description
ThreadedCommentCollection

The threaded comment collection.

Remarks

Note

The Spreadsheet Document API does not print or export threaded comments to PDF format.

Create a New Comment

Call the ThreadedCommentCollection.Add method to add a threaded comment to a specific cell. If you pass a cell range as the method parameter, the comment is added to the top-left cell of this range.

You can pass a string or a ThreadedCommentAuthor instance to specify a comment author. The ThreadedCommentAuthor object allows you to specify login credentials that link the author to their identity provider (Windows Live ID, Office 365, and so on).

The code sample below adds a comment to the G16 cell:

var workbook = new Workbook();
workbook.LoadDocument(@"C:\Docs\Comments.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
var comments = worksheet.ThreadedComments;

ThreadedComment threadedComment =
    comments.Add(worksheet["G16"], "Sales Department",
         "The discount was approved by the Sales Director at the meeting on November 5th.");
threadedComment.Resolved = true;

workbook.SaveDocument(@"C:\Docs\Comments_upd.xlsx");

Reply to a Comment

Use the ThreadedComment.Reply method to add a reply. You can pass a string or a ThreadedCommentAuthor instance to specify a comment author.

Use the ThreadedComment.Replies property to access replies in a thread. You can edit or remove replies as your needs dictate.

The code sample below adds a reply to the first comment:

using DevExpress.Spreadsheet;

var workbook = new Workbook();
workbook.LoadDocument(@"C:\Docs\Comments.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
var comments = worksheet.ThreadedComments;

ThreadedComment threadedComment = comments[0];
threadedComment.Reply("Nancy Davolio", "Thanks for the hint");
workbook.SaveDocument(@"C:\Docs\Comments_upd.xlsx");

Retrieve Comments

Call the GetThreadedComments method to obtain all comments added to the specified cell range.

The code sample below obtains all comments added to the A1:G20 cell range:

using DevExpress.Spreadsheet;

var workbook = new Workbook();
workbook.LoadDocument(@"C:\Docs\Comments.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
var comments = worksheet.ThreadedComments.GetThreadedComments(worksheet["A1:G20"]);

Remove a Comment

The following methods allow you to remove comments:

ThreadedCommentCollection.Remove
Removes the specified comments or a comment applied to a cell range.
ThreadedCommentCollection.RemoveAt
Removes a comment at the specified index in the collection.

The code sample below removes all comments with the specified author:

var workbook = new Workbook();
workbook.LoadDocument(@"C:\Docs\Comments.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
var comments = worksheet.ThreadedComments.Where(comment => comment.Author.Name == "Nancy Davolio");
if (comments!=null)
{
    foreach (var comment in comments)
    {
        worksheet.ThreadedComments.Remove(comment);
    }
}
See Also