[]
        
(Showing Draft Content)

Threaded Comments

Threaded comment refers to the spreadsheet comments which appear as a conversation or discussion. These comments provide a reply box which allows users to respond on a comment resulting into a conversation.

GcExcel.NET allows you to add threaded comments through ICommentThreaded interface. Each comment in the collection of threaded comments on a particular worksheet is represented by ICommentsThreaded object. The comments are stored in collection in the order of row and then column.


Note: A threaded comment is converted into a comment when the worksheet is exported to JSON.

Create Threaded Comments

To create threaded comment to a worksheet cell, you can use AddCommentThreaded method of the IRange interface. This method accepts comment text and author's name as its parameters.

// Create threaded comment for range C3.
ICommentThreaded commentThreadedC3 = worksheet.Range["C3"].AddCommentThreaded("Do these sales numbers include the subsidiary divisions?", "Bill");

// Add a reply for commentThreadedC3.
ICommentThreaded Reply = commentThreadedC3.AddReply("Yes, they do.", "Even");

Add Reply to Threaded Comment

To add reply to a threaded comment, you can use AddReply method of the ICommentsThreaded interface. The method adds the reply to collection of replies if the threaded comment is a top-level threaded comment. In case the threaded comment is a reply, the method adds reply to the parent's collection of replies. The collection of replies can be fetched using Replies property.

// Add replies for commentThreadedC3.
ICommentThreaded Reply_1 = commentThreadedC3.AddReply("Mark's reply", "Mark");
ICommentThreaded Reply_2 = commentThreadedC3.AddReply("Bill's reply", "Bill");

Modify Threaded Comment

To modify a threaded comment, you can set Text property of the threaded comment to a new string.

// Sets a new text for commentTHreadedC3.
commentThreadedC3.Text = "New Content";

// Delete Reply_1
Reply_1.Delete();

// Sets a new text for Reply_2.
Reply_2.Text = "Bill's new reply";

Read Threaded Comment

GcExcel.NET provides various properties using which you can read the threaded comments and their attributes such as date stamp, author etc. To fetch the whole collection of threaded comments on a worksheet, you can use the IWorksheet.CommentsThreaded method, while a specific threaded comment can be obtained from ICommentsThreaded collection by using the I****ndex property**.** You can also get the number of total comments on a worksheet by using the Count property. The ICommentsThreaded interface also provides Parent property to get parent if the threaded comment is a reply. To read the date stamp or author of a comment, you can use Date and Author properties. You can also fetch Next or Previous comments of a threaded comment in a worksheet.

// Get a specific comment
Console.WriteLine("Get a specific comment : " + worksheet.CommentsThreaded[0].Text);

// Get replies count
Console.WriteLine("Replies Count : " + commentThreadedC3.Replies.Count);

// Get all replies on a specific comment
for (int i = 0; i < commentThreadedC3.Replies.Count; i++)
    Console.WriteLine("Get replies text[" + i + "] : " + commentThreadedC3.Replies[i].Text);

// Get author of comment
Console.WriteLine("Author Name : " + commentThreadedC3.Author.Name.ToString());

// Get collection of threaded comments
Console.WriteLine("Get collection of threaded comments : " + worksheet.CommentsThreaded.Count);

// Get Date stamp of comment
Console.WriteLine("Date of Comment : " + commentThreadedC3.Date.ToShortDateString());

// Get Time stamp of comment
Console.WriteLine("Time of Comment : " + commentThreadedC3.Date.ToShortTimeString());

// Get C3's next comment
Console.WriteLine("C3's next comment : " + commentThreadedC3.Next().Text);

// Get D3's previous comment
Console.WriteLine("D3's previous comment : " + commentThreadedD3.Previous().Text);

// Get parent of a reply    
Console.WriteLine("Parent of Reply_1 : " + Reply_1.Parent.Text);
Console.WriteLine("Parent of Reply_2 : " + Reply_2.Parent.Text);

Below is the outcome displayed on console after above processing:


Disable Threaded Comment

GcExcel.NET provides IsResolved property to set the resolve status of a threaded comment. Setting this property to true also means, that the threaded comment is disabled and user cannot edit or reply to that comment.

//Disable threaded comment
commentThreadedC3.IsResolved = true;

Clear Threaded Comment

To delete a threaded comment and replies associated with that comment, you can use the ICommentThreaded.Delete method. If the target CommentThreaded object is a top-level comment, this method removes the specified comment. However, if the target comment is a reply in one of the comment threads, this method removes that reply from reply collection of the parent comment. You can also clear threaded comments from a range of cells by using the IRange.ClearCommentsThreaded method.

// Create threaded comment for range C3.
ICommentThreaded commentThreadedE3 = worksheet.Range["E3"].AddCommentThreaded("Range E3's threaded comment", "Even");

// Add a reply for commentThreadedC3.
worksheet.Range["F3"].AddCommentThreaded("Range F3's threaded comment", "Charles");
#region Delete
// Delete a single cell threaded comment.
commentThreadedE3.Delete();
        
// Clear a range of cells threaded comment.
worksheet.Range["F3:G4"].ClearCommentsThreaded();

Set Author Name

To set author of a comment, you can use Name property of the IAuthor interface.

//Set author name
IAuthor author = commentThreadedC3.Author;
author.Name = "Alex";