FThreadComment
| packages | @univerjs/sheets-thread-comment |
|---|
A class that represents a thread comment already in the sheet.
APIs
delete
Deprecated
use deleteAsync as instead.
Signature
delete(): Promise<boolean>deleteAsync
Delete the comment and it's replies
Signature
deleteAsync(): Promise<boolean>Returns
- (
Promise<boolean>) — Whether the comment is deleted successfully
Examples
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
Get the comment data
Signature
getCommentData(): IBaseCommentReturns
- (
IBaseComment) — The comment data
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()
const comments = fWorksheet.getComments()
comments.forEach((comment) => {
console.log(comment.getCommentData())
})getContent
Deprecated
use getRichText as instead
Signature
getContent(): IDocumentBodygetIsRoot
Whether the comment is a root comment
Signature
getIsRoot(): booleanReturns
- (
boolean) — Whether the comment is a root comment
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()
const comments = fWorksheet.getComments()
comments.forEach((comment) => {
console.log(comment.getIsRoot())
})getRange
Get the range of the comment
Signature
getRange(): FRange | nullReturns
- (
FRange | null) — The range of the comment
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()
const comments = fWorksheet.getComments()
comments.forEach((comment) => {
console.log(comment.getRange().getA1Notation())
})getReplies
Get the replies of the comment
Signature
getReplies(): FThreadComment[] | undefinedReturns
- (
FThreadComment[] | undefined) — the replies of the comment
Examples
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
Get the rich text of the comment
Signature
getRichText(): RichTextValueReturns
- (
RichTextValue) — The rich text of the comment
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()
const comments = fWorksheet.getComments()
comments.forEach((comment) => {
console.log(comment.getRichText())
})replyAsync
Reply to the comment
Signature
replyAsync(comment: FTheadCommentBuilder): Promise<boolean>Parameters
comment(FTheadCommentBuilder) — The comment to reply to
Returns
- (
Promise<boolean>) — Whether the comment is replied successfully
Examples
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
Deprecated
use resolveAsync as instead
Signature
resolve(resolved?: boolean): Promise<boolean>resolveAsync
Resolve the comment
Signature
resolveAsync(resolved?: boolean): Promise<boolean>Parameters
resolved(boolean) — Whether the comment is resolved
Returns
- (
Promise<boolean>) — Set the comment to resolved or not operation result
Examples
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
Deprecated
use updateAsync as instead
Signature
update(content: IDocumentBody): Promise<boolean>updateAsync
Update the comment content
Signature
updateAsync(content: IDocumentBody | RichTextValue): Promise<boolean>Parameters
content(IDocumentBody | RichTextValue) — The new content of the comment
Returns
- (
Promise<boolean>) — Whether the comment is updated successfully
Examples
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)