Thread Comment
| Packages | @univerjs/sheets-thread-comment |
|---|
A class that represents a thread comment already in the sheet.
Overview
@univerjs/sheets-thread-comment
| Method | Description |
|---|---|
build | Build the comment |
copy | Copy the comment |
create | Create a new FTheadCommentItem |
delete | - |
deleteAsync | Delete the comment and it's replies |
getCommentData | Get the comment data |
getContent | - |
getIsRoot | Whether the comment is a root comment |
getRange | Get the range of the comment |
getReplies | Get the replies of the comment |
getRichText | Get the rich text of the comment |
replyAsync | Reply to the comment |
resolve | - |
resolveAsync | Resolve the comment |
setContent | Set the content of the comment |
setDateTime | Set the date time of the comment |
setId | Set the id of the comment |
setPersonId | Set the person id of the comment |
setThreadId | Set the thread id of the comment |
update | - |
updateAsync | Update the comment content |
APIs
Lifecycle & Creation
build
Build the comment
Signature
build(): IThreadCommentReturns
IThreadComment— The comment
Examples
const richText = univerAPI.newRichText().insertText('hello univer');
const comment = univerAPI.newTheadComment()
.setContent(richText)
.setPersonId('mock-user-id')
.setDateTime(new Date('2025-02-21 14:22:22'))
.setId('mock-comment-id')
.setThreadId('mock-thread-id')
.build();
console.log(comment);@univerjs/sheets-thread-comment
create
Create a new FTheadCommentItem
Signature
static create(comment?: IThreadComment): FTheadCommentItemParameters
commentIThreadComment(optional) — No description
Returns
FTheadCommentItem— A new instance of FTheadCommentItem
Examples
const commentBuilder = univerAPI.newTheadComment();
console.log(commentBuilder);@univerjs/sheets-thread-comment
Getters & Queries
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());
});@univerjs/sheets-thread-comment
getContent
getRichText as insteadSignature
getContent(): IDocumentBodyReturns
IDocumentBody— See signature above.
@univerjs/sheets-thread-comment
getIsRoot
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());
});@univerjs/sheets-thread-comment
getRange
Get the range of the comment
Signature
getRange(): FRange | nullReturns
any— 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());
});@univerjs/sheets-thread-comment
getReplies
Get the replies of the comment
Signature
getReplies(): FThreadComment[] | undefinedReturns
FThreadComment[]— 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());
});
}
});@univerjs/sheets-thread-comment
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());
});@univerjs/sheets-thread-comment
Setters & Modifiers
setContent
Set the content of the comment
Signature
setContent(content: IDocumentBody | RichTextValue): FTheadCommentBuilderParameters
contentIDocumentBody | RichTextValue— No description
Returns
FTheadCommentBuilder— The comment builder for chaining
Examples
// Create a new comment
const richText = univerAPI.newRichText().insertText('hello univer');
const commentBuilder = univerAPI.newTheadComment()
.setContent(richText);
console.log(commentBuilder.content);
// Add the comment to the cell A1
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const cell = fWorksheet.getRange('A1');
const result = await cell.addCommentAsync(commentBuilder);
console.log(result);@univerjs/sheets-thread-comment
setDateTime
Set the date time of the comment
Signature
setDateTime(date: Date): FTheadCommentBuilderParameters
dateDate— No description
Returns
FTheadCommentBuilder— The comment builder for chaining
Examples
// Create a new comment
const richText = univerAPI.newRichText().insertText('hello univer');
const commentBuilder = univerAPI.newTheadComment()
.setContent(richText)
.setDateTime(new Date('2025-02-21 14:22:22'));
console.log(commentBuilder.dateTime);
// Add the comment to the cell A1
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const cell = fWorksheet.getRange('A1');
const result = await cell.addCommentAsync(commentBuilder);
console.log(result);@univerjs/sheets-thread-comment
setId
Set the id of the comment
Signature
setId(id: string): FTheadCommentBuilderParameters
idstring— No description
Returns
FTheadCommentBuilder— The comment builder for chaining
Examples
// Create a new comment
const richText = univerAPI.newRichText().insertText('hello univer');
const commentBuilder = univerAPI.newTheadComment()
.setContent(richText)
.setId('mock-comment-id');
console.log(commentBuilder.id);
// Add the comment to the cell A1
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const cell = fWorksheet.getRange('A1');
const result = await cell.addCommentAsync(commentBuilder);
console.log(result);@univerjs/sheets-thread-comment
setPersonId
Set the person id of the comment
Signature
setPersonId(userId: string): FTheadCommentBuilderParameters
userIdstring— No description
Returns
FTheadCommentBuilder— The comment builder for chaining
Examples
// Create a new comment
const richText = univerAPI.newRichText().insertText('hello univer');
const commentBuilder = univerAPI.newTheadComment()
.setContent(richText)
.setPersonId('mock-user-id');
console.log(commentBuilder.personId);
// Add the comment to the cell A1
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const cell = fWorksheet.getRange('A1');
const result = await cell.addCommentAsync(commentBuilder);
console.log(result);@univerjs/sheets-thread-comment
setThreadId
Set the thread id of the comment
Signature
setThreadId(threadId: string): FTheadCommentBuilderParameters
threadIdstring— No description
Returns
FTheadCommentBuilder— The comment builder
Examples
// Create a new comment
const richText = univerAPI.newRichText().insertText('hello univer');
const commentBuilder = univerAPI.newTheadComment()
.setContent(richText)
.setThreadId('mock-thread-id');
console.log(commentBuilder.threadId);
// Add the comment to the cell A1
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const cell = fWorksheet.getRange('A1');
const result = await cell.addCommentAsync(commentBuilder);
console.log(result);@univerjs/sheets-thread-comment
update
updateAsync as insteadSignature
async update(content: IDocumentBody): Promise<boolean>Parameters
contentIDocumentBody— No description
Returns
Promise<boolean>— See signature above.
@univerjs/sheets-thread-comment
updateAsync
Update the comment content
Signature
async updateAsync(content: IDocumentBody | RichTextValue): Promise<boolean>Parameters
contentIDocumentBody | RichTextValue— No description
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);@univerjs/sheets-thread-comment
Actions & Operations
copy
Copy the comment
Signature
copy(): FTheadCommentBuilderReturns
FTheadCommentBuilder— The comment builder
Examples
const commentBuilder = univerAPI.newTheadComment();
const newCommentBuilder = commentBuilder.copy();
console.log(newCommentBuilder);@univerjs/sheets-thread-comment
delete
deleteAsync as instead.Signature
delete(): Promise<boolean>Returns
Promise<boolean>— See signature above.
@univerjs/sheets-thread-comment
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);@univerjs/sheets-thread-comment
Miscellaneous
replyAsync
Reply to the comment
Signature
replyAsync(comment: FTheadCommentBuilder): Promise<boolean>Parameters
commentFTheadCommentBuilder— No description
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);@univerjs/sheets-thread-comment
resolve
resolveAsync as insteadSignature
resolve(resolved?: boolean): Promise<boolean>Parameters
resolvedboolean(optional) — No description
Returns
Promise<boolean>— See signature above.
@univerjs/sheets-thread-comment
resolveAsync
Resolve the comment
Signature
resolveAsync(resolved?: boolean): Promise<boolean>Parameters
resolvedboolean(optional) — No description
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);@univerjs/sheets-thread-comment