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.
DsExcel Java allows you to add threaded comments through ICommentThreaded interface. Each comment in the collection of threaded comments on a particular worksheet is represented by ICommentThreaded object. The comments are stored in collection in the order of row and then column.
To create threaded comment to a worksheet cell, you can use addCommentThread method of the IRange interface. This method accepts comment text and author's name as its parameters.
Java |
Copy Code |
---|---|
// Create threaded comment for range C3. ICommentThreaded commentThreadedC3 = worksheet.getRange("C3").addCommentThreaded("Range C3's threaded comment","Bill"); // Add a reply for commentThreadedC3. ICommentThreaded Reply = commentThreadedC3.addReply("Range C3's reply","Even"); |
To add reply to a threaded comment, you can use addReply method of the ICommentThreaded 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 the getReplies method.
Java |
Copy Code |
---|---|
// Add replies for commentThreadedC3. ICommentThreaded Reply_1 = commentThreadedC3.addReply("Mark's reply", "Mark"); ICommentThreaded Reply_2 = commentThreadedC3.addReply("Bill's reply", "Bill"); |
To modify a threaded comment, you can use the setText method of the threaded comment to set a new string.
Java |
Copy Code |
---|---|
// Sets a new text for commentTHreadedC3. commentThreadedC3.setText("New Content"); // Delete Reply_1 Reply_1.delete(); // Sets a new text for Reply_2. Reply_2.setText("Bill's new reply"); |
DsExcel Java 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.getCommentsThreaded method, while a specific threaded comment can be obtained from ICommentThreaded collection by using the get method. You can also get the number of total comments on a worksheet by using the getCount method. The ICommentsThreaded interface also provides getParent method to get parent if the threaded comment is a reply. To read the date stamp or author of a comment, you can use DateTime and getAuthor methods. You can also fetch next or previous comments of a threaded comment in a worksheet.
Java |
Copy Code |
---|---|
// Get a specific comment System.out.println("Get a specific comment : " + worksheet.getCommentsThreaded().get(0).getText()); // Get replies count System.out.println("Replies Count : " + commentThreadedC3.getReplies().getCount()); // Get all replies on a specific comment for (int i = 0; i < commentThreadedC3.getReplies().getCount(); i++) System.out.println("Get replies text[" + i + "] : " + commentThreadedC3.getReplies().get(i).getText()); // Get author of comment System.out.println("Author Name : " + commentThreadedC3.getAuthor().getName().toString()); // Get collection of threaded comments System.out.println("Get collection of threaded comments : " + worksheet.getCommentsThreaded().getCount()); // Get Date stamp of comment Date date = commentThreadedC3.DateTime(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); String strDate = dateFormat.format(date); System.out.println("Date of Comment : " + strDate); // Get Time stamp of comment Date time = commentThreadedC3.DateTime(); DateFormat timeFormat = new SimpleDateFormat("hh:mm:ss"); String strTime = timeFormat.format(time); System.out.println("Time of Comment : " + strTime); // Get C3's next comment System.out.println("C3's next comment : " + commentThreadedC3.next().getText()); // Get D3's previous comment System.out.println("D3's previous comment : " + commentThreadedD3.previous().getText()); // Get parent of a reply System.out.println("Parent of Reply_1 : " + Reply_1.getParent().getText()); System.out.println("Parent of Reply_2 : " + Reply_2.getParent().getText()); |
Below is the outcome displayed on console after above processing:
DsExcel Java provides setIsResolved method to set the resolve status of a threaded comment. Setting this method to true also means, that the threaded comment is disabled and user cannot edit or reply to that comment.
Java |
Copy Code |
---|---|
commentThreadedC3.setIsResolved(true); |
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.
Java |
Copy Code |
---|---|
// Delete a single cell threaded comment. commentThreadedE3.delete(); // Clear a range of cells threaded comment. worksheet.getRange("F3:G4").clearCommentsThreaded(); |
To set author of a comment, you can use setName method of the IAuthor interface.
Java |
Copy Code |
---|---|
//Set author name IAuthor author = commentThreadedC3.getAuthor(); author.setName("Alex"); |