Comments
Since R2 2022 the SpreadProcessing library supports working with comments. Comments are used for marking information about a cell's data and can have one or multiple Replies. All comments can be found in the Comments property of the worksheet, which is of the type CommentCollection. This collection holds SpreadsheetComment objects, which represent the comments. Each comment has the following members:
Properties:
- CellIndex: Gets or sets the cell index the comment is assigned to.
- Text: Gets or sets the text of the comment.
- CreationDate: Gets or sets the date when the comment is created. Nullable.
- Author: Gets or sets the author assigned to the comment.
- Replies: Gets the comment replies. The list is sorted by CreationDate.
-
IsResolved: Gets or sets a value indicating whether the comment is resolved.
All of the above properties will push a change to the undo stack when modified.
Methods:
- AddReply: Adds a SpreadsheetCommentReply to the ReplySortedCollection. The collection will be re-sorted by SpreadsheetReply`s CreationDate in ascending order after adding an object.
- RemoveReply: Removes the specified reply from the collection.
Working with CommentCollection
Adding comments
To add a comment you need to specify the cell index to which the comment will be related, the author, the text content, and the creation date. Specifying the creation date is optional and by default, its value is the current date and time.
Example 1: Add comment
Removing Comments
To remove a comment, you should specify the comment instance. This instance can be obtained from the CommentCollection.
Example 2: Remove comment
Replies
Each comment can be replied to, forming a thread of information. All replies can be found in the Replies property of the comment, which is of the type ReplySortedCollection. This collection holds SpreadsheetCommentReply objects which represent the replies. The ReplySortedCollection has the following members:
Properties:
- Count: Gets the number of elements contained in the ReplySortedCollection.
Methods:
- Add: Adds a SpreadsheetCommentReply to the ReplySortedCollection. The collection will be re-sorted by SpreadsheetReply`s CreationDate in ascending order after adding an object. Requires an object of type SpreadsheetCommentReply and can be used for adding existing replies. For adding a new reply, it is best to use the SpreadsheetComment.AddReply() method.
- Remove: Removes the specified SpreadsheetCommentReply object from the ReplySortedCollection.
- RemoveAt: Removes the element at the specified index of the ReplySortedCollection.
- Clear: Removes all elements from the ReplySortedCollection.
- Contains: Determines whether an element is in the ReplySortedCollection.
- CopyTo: Copies the entire ReplySortedCollection to a compatible one-dimensional array, starting at the specified index of the target array.
Example 3: Working with Replies
Events
Both CommentCollection and ReplySortedCollection expose the following events, which work identically for both types:
- Changing: Occurs prior to changing the collection.
- Changed: Occurs after the collection has changed.
The two events for both collections use similar enumeration types for event arguments, with two possible values:
- Add: Used when Adding a Comment or Reply
- Remove: Used when Removing a Comment or Reply