类: FThreadComment
A class that represents a thread comment already in the sheet.
方法
delete()
delete(): Promise<boolean>;返回
Promise<boolean>
已被弃用
use deleteAsync as instead.
deleteAsync()
deleteAsync(): Promise<boolean>;Delete the comment and it’s replies
返回
Promise<boolean>
Whether the comment is deleted successfully
示例
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
返回
IBaseComment
The comment data
示例
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const comments = fWorksheet.getComments();
comments.forEach((comment) => {
console.log(comment.getCommentData());
});getContent()
getContent(): IDocumentBody;返回
已被弃用
use getRichText as instead
getIsRoot()
getIsRoot(): boolean;Whether the comment is a root comment
返回
boolean
Whether the comment is a root comment
示例
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
返回
The range of the comment
示例
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
返回
FThreadComment[]
the replies of the comment
示例
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
返回
RichTextValue
The rich text of the comment
示例
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
参数
| 参数 | 类型 | 描述 |
|---|---|---|
comment | FTheadCommentBuilder | The comment to reply to |
返回
Promise<boolean>
Whether the comment is replied successfully
示例
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>;参数
| 参数 | 类型 |
|---|---|
resolved? | boolean |
返回
Promise<boolean>
已被弃用
use resolveAsync as instead
resolveAsync()
resolveAsync(resolved?): Promise<boolean>;Resolve the comment
参数
| 参数 | 类型 | 描述 |
|---|---|---|
resolved? | boolean | Whether the comment is resolved |
返回
Promise<boolean>
Set the comment to resolved or not operation result
示例
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>;参数
| 参数 | 类型 |
|---|---|
content | IDocumentBody |
返回
Promise<boolean>
已被弃用
use updateAsync as instead
updateAsync()
updateAsync(content): Promise<boolean>;Update the comment content
参数
| 参数 | 类型 | 描述 |
|---|---|---|
content | any | The new content of the comment |
返回
Promise<boolean>
Whether the comment is updated successfully
示例
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);