Class: FThreadComment
A class that represents a thread comment already in the sheet.
Methods
delete()
delete(): Promise<boolean>;Returns
Promise<boolean>
Deprecated
use deleteAsync as instead.
deleteAsync()
deleteAsync(): Promise<boolean>;Delete the comment and it’s replies
Returns
Promise<boolean>
Whether the comment is deleted successfully
Example
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const comments = fWorksheet.getComments();
// Delete the first comment
const result = await comments[0]?.deleteAsync();
console.log(result);getCommentData()
getCommentData(): IBaseComment;Get the comment data
Returns
IBaseComment
The comment data
Example
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const comments = fWorksheet.getComments();
comments.forEach((comment) => {
console.log(comment.getCommentData());
});getContent()
getContent(): IDocumentBody;Returns
Deprecated
use getRichText as instead
getIsRoot()
getIsRoot(): boolean;Whether the comment is a root comment
Returns
boolean
Whether the comment is a root comment
Example
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const comments = fWorksheet.getComments();
comments.forEach((comment) => {
console.log(comment.getIsRoot());
});getRange()
getRange(): FRange;Get the range of the comment
Returns
The range of the comment
Example
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const comments = fWorksheet.getComments();
comments.forEach((comment) => {
console.log(comment.getRange().getA1Notation());
});getReplies()
getReplies(): FThreadComment[];Get the replies of the comment
Returns
FThreadComment[]
the replies of the comment
Example
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const comments = fWorksheet.getComments();
comments.forEach((comment) => {
if (comment.getIsRoot()) {
const replies = comment.getReplies();
replies.forEach((reply) => {
console.log(reply.getCommentData());
});
}
});getRichText()
getRichText(): RichTextValue;Get the rich text of the comment
Returns
RichTextValue
The rich text of the comment
Example
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const comments = fWorksheet.getComments();
comments.forEach((comment) => {
console.log(comment.getRichText());
});replyAsync()
replyAsync(comment): Promise<boolean>;Reply to the comment
Parameters
| Parameter | Type | Description |
|---|---|---|
comment | FTheadCommentBuilder | The comment to reply to |
Returns
Promise<boolean>
Whether the comment is replied successfully
Example
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
// Create a new comment
const richText = univerAPI.newRichText().insertText('hello univer');
const commentBuilder = univerAPI.newTheadComment()
.setContent(richText)
.setId('mock-comment-id');
const cell = fWorksheet.getRange('A1');
await cell.addCommentAsync(commentBuilder);
// Reply to the comment
const replyText = univerAPI.newRichText().insertText('Hello Univer AI');
const reply = univerAPI.newTheadComment().setContent(replyText);
const comment = fWorksheet.getCommentById('mock-comment-id');
const result = await comment.replyAsync(reply);
console.log(result);resolve()
resolve(resolved?): Promise<boolean>;Parameters
| Parameter | Type |
|---|---|
resolved? | boolean |
Returns
Promise<boolean>
Deprecated
use resolveAsync as instead
resolveAsync()
resolveAsync(resolved?): Promise<boolean>;Resolve the comment
Parameters
| Parameter | Type | Description |
|---|---|---|
resolved? | boolean | Whether the comment is resolved |
Returns
Promise<boolean>
Set the comment to resolved or not operation result
Example
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
// Create a new comment
const richText = univerAPI.newRichText().insertText('hello univer');
const commentBuilder = univerAPI.newTheadComment()
.setContent(richText)
.setId('mock-comment-id');
const cell = fWorksheet.getRange('A1');
await cell.addCommentAsync(commentBuilder);
// Resolve the comment after 3 seconds
setTimeout(async () => {
const comment = fWorksheet.getCommentById('mock-comment-id');
const result = await comment.resolveAsync(true);
console.log(result);
}, 3000);update()
update(content): Promise<boolean>;Parameters
| Parameter | Type |
|---|---|
content | IDocumentBody |
Returns
Promise<boolean>
Deprecated
use updateAsync as instead
updateAsync()
updateAsync(content): Promise<boolean>;Update the comment content
Parameters
| Parameter | Type | Description |
|---|---|---|
content | any | The new content of the comment |
Returns
Promise<boolean>
Whether the comment is updated successfully
Example
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
// Create a new comment
const richText = univerAPI.newRichText().insertText('hello univer');
const commentBuilder = univerAPI.newTheadComment()
.setContent(richText)
.setId('mock-comment-id');
const cell = fWorksheet.getRange('A1');
await cell.addCommentAsync(commentBuilder);
// Update the comment after 3 seconds
setTimeout(async () => {
const comment = fWorksheet.getCommentById('mock-comment-id');
const newRichText = univerAPI.newRichText().insertText('Hello Univer AI');
const result = await comment.updateAsync(newRichText);
console.log(result);
}, 3000);