FThreadComment
A class that represents a thread comment already in the sheet.
Access
Access through:
FRange.getComment()FRange.getComments()FWorkbook.getComments()FWorksheet.getComments()FWorksheet.getCommentById()
Setup
Register @univerjs/sheets-thread-comment or a preset that includes it. In plugin mode, import @univerjs/sheets-thread-comment/facade. Additional methods below require their listed plugin packages. See Facade setup.
@univerjs/sheets-thread-comment
FThreadComment.deleteAsync
Delete the comment and it's replies
deleteAsync(): Promise<boolean>Returns
Whether the comment is deleted successfully
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const comments = fWorksheet.getComments()// Delete the first commentconst result = await comments[0]?.deleteAsync()console.log(result)Types: Promise
Package: @univerjs/sheets-thread-comment · Type definitions
FThreadComment.getCommentData
Get the comment data
getCommentData(): IBaseCommentReturns
The comment data
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const comments = fWorksheet.getComments()comments.forEach((comment) => { console.log(comment.getCommentData())})Types: IBaseComment
Package: @univerjs/sheets-thread-comment · Type definitions
FThreadComment.getIsRoot
Whether the comment is a root comment
getIsRoot(): booleanReturns
Whether the comment is a root comment
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const comments = fWorksheet.getComments()comments.forEach((comment) => { console.log(comment.getIsRoot())})Package: @univerjs/sheets-thread-comment · Type definitions
FThreadComment.getRange
Get the range of the comment
getRange(): FRange | nullReturns
The range of the comment
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const comments = fWorksheet.getComments()comments.forEach((comment) => { console.log(comment.getRange().getA1Notation())})Types: FRange
Package: @univerjs/sheets-thread-comment · Type definitions
FThreadComment.getReplies
Get the replies of the comment
getReplies(): FThreadComment[] | undefinedReturns
The loaded replies, or undefined when the thread or its replies are unavailable.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const comments = fWorksheet.getComments()comments.forEach((comment) => { if (comment.getIsRoot()) { const replies = comment.getReplies() replies.forEach((reply) => { console.log(reply.getCommentData()) }) }})Types: FThreadComment
Package: @univerjs/sheets-thread-comment · Type definitions
FThreadComment.getRichText
Get the rich text of the comment
getRichText(): RichTextValueReturns
The rich text of the comment
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const comments = fWorksheet.getComments()comments.forEach((comment) => { console.log(comment.getRichText())})Types: RichTextValue
Package: @univerjs/sheets-thread-comment · Type definitions
FThreadComment.replyAsync
Reply to the comment
replyAsync(comment: FTheadCommentBuilder): Promise<boolean>Parameters
comment— Required. The comment to reply to
Returns
Whether the comment is replied successfully
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Create a new commentconst 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 commentconst 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)Types: Promise · FTheadCommentBuilder
Package: @univerjs/sheets-thread-comment · Type definitions
FThreadComment.resolveAsync
Resolve the comment
resolveAsync(resolved?: boolean): Promise<boolean>Parameters
resolved— Optional. Whether the comment is resolved
Returns
Set the comment to resolved or not operation result
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Create a new commentconst 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 secondssetTimeout(async () => { const comment = fWorksheet.getCommentById('mock-comment-id') const result = await comment.resolveAsync(true) console.log(result)}, 3000)Types: Promise
Package: @univerjs/sheets-thread-comment · Type definitions
FThreadComment.updateAsync
Update the comment content
updateAsync(content: IDocumentBody | RichTextValue): Promise<boolean>Parameters
content— Required. The new content of the comment
Returns
Whether the comment is updated successfully
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Create a new commentconst 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 secondssetTimeout(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)Types: Promise · IDocumentBody · RichTextValue
Package: @univerjs/sheets-thread-comment · Type definitions
How is this guide?