Thread Comment

GitHubEdit on GitHub
Packages@univerjs/sheets-thread-comment
CORE

A class that represents a thread comment already in the sheet.

Overview

@univerjs/sheets-thread-comment

MethodDescription
buildBuild the comment
copyCopy the comment
createCreate a new FTheadCommentItem
delete-
deleteAsyncDelete the comment and it's replies
getCommentDataGet the comment data
getContent-
getIsRootWhether the comment is a root comment
getRangeGet the range of the comment
getRepliesGet the replies of the comment
getRichTextGet the rich text of the comment
replyAsyncReply to the comment
resolve-
resolveAsyncResolve the comment
setContentSet the content of the comment
setDateTimeSet the date time of the comment
setIdSet the id of the comment
setPersonIdSet the person id of the comment
setThreadIdSet the thread id of the comment
update-
updateAsyncUpdate the comment content

APIs

Lifecycle & Creation

build

Build the comment

Signature

build(): IThreadComment

Returns

  • 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);
Source: @univerjs/sheets-thread-comment

create

Create a new FTheadCommentItem

Signature

static create(comment?: IThreadComment): FTheadCommentItem

Parameters

  • comment IThreadComment (optional)No description

Returns

  • FTheadCommentItem — A new instance of FTheadCommentItem

Examples

const commentBuilder = univerAPI.newTheadComment();
console.log(commentBuilder);
Source: @univerjs/sheets-thread-comment

Getters & Queries

getCommentData

Get the comment data

Signature

getCommentData(): IBaseComment

Returns

  • IBaseComment — The comment data

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const comments = fWorksheet.getComments();
comments.forEach((comment) => {
  console.log(comment.getCommentData());
});
Source: @univerjs/sheets-thread-comment

getContent

Deprecated — use getRichText as instead

Signature

getContent(): IDocumentBody

Returns

  • IDocumentBody — See signature above.
Source: @univerjs/sheets-thread-comment

getIsRoot

Whether the comment is a root comment

Signature

getIsRoot(): boolean

Returns

  • 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());
});
Source: @univerjs/sheets-thread-comment

getRange

Get the range of the comment

Signature

getRange(): FRange | null

Returns

  • 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());
});
Source: @univerjs/sheets-thread-comment

getReplies

Get the replies of the comment

Signature

getReplies(): FThreadComment[] | undefined

Returns

  • 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());
    });
  }
});
Source: @univerjs/sheets-thread-comment

getRichText

Get the rich text of the comment

Signature

getRichText(): RichTextValue

Returns

  • 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());
});
Source: @univerjs/sheets-thread-comment

Setters & Modifiers

setContent

Set the content of the comment

Signature

setContent(content: IDocumentBody | RichTextValue): FTheadCommentBuilder

Parameters

  • content IDocumentBody | RichTextValueNo 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);
Source: @univerjs/sheets-thread-comment

setDateTime

Set the date time of the comment

Signature

setDateTime(date: Date): FTheadCommentBuilder

Parameters

  • date DateNo 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);
Source: @univerjs/sheets-thread-comment

setId

Set the id of the comment

Signature

setId(id: string): FTheadCommentBuilder

Parameters

  • id stringNo 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);
Source: @univerjs/sheets-thread-comment

setPersonId

Set the person id of the comment

Signature

setPersonId(userId: string): FTheadCommentBuilder

Parameters

  • userId stringNo 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);
Source: @univerjs/sheets-thread-comment

setThreadId

Set the thread id of the comment

Signature

setThreadId(threadId: string): FTheadCommentBuilder

Parameters

  • threadId stringNo 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);
Source: @univerjs/sheets-thread-comment

update

Deprecated — use updateAsync as instead

Signature

async update(content: IDocumentBody): Promise<boolean>

Parameters

  • content IDocumentBodyNo description

Returns

  • Promise<boolean> — See signature above.
Source: @univerjs/sheets-thread-comment

updateAsync

Update the comment content

Signature

async updateAsync(content: IDocumentBody | RichTextValue): Promise<boolean>

Parameters

  • content IDocumentBody | RichTextValueNo 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);
Source: @univerjs/sheets-thread-comment

Actions & Operations

copy

Copy the comment

Signature

copy(): FTheadCommentBuilder

Returns

  • FTheadCommentBuilder — The comment builder

Examples

const commentBuilder = univerAPI.newTheadComment();
const newCommentBuilder = commentBuilder.copy();
console.log(newCommentBuilder);
Source: @univerjs/sheets-thread-comment

delete

Deprecated — use deleteAsync as instead.

Signature

delete(): Promise<boolean>

Returns

  • Promise<boolean> — See signature above.
Source: @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);
Source: @univerjs/sheets-thread-comment

Miscellaneous

replyAsync

Reply to the comment

Signature

replyAsync(comment: FTheadCommentBuilder): Promise<boolean>

Parameters

  • comment FTheadCommentBuilderNo 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);
Source: @univerjs/sheets-thread-comment

resolve

Deprecated — use resolveAsync as instead

Signature

resolve(resolved?: boolean): Promise<boolean>

Parameters

  • resolved boolean (optional)No description

Returns

  • Promise<boolean> — See signature above.
Source: @univerjs/sheets-thread-comment

resolveAsync

Resolve the comment

Signature

resolveAsync(resolved?: boolean): Promise<boolean>

Parameters

  • resolved boolean (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);
Source: @univerjs/sheets-thread-comment