Comment
This topic describes the API operations that are related to the Comment object of text documents.
Comments
ActiveDocument.Comments
Obtains all comments from a document.
Only JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Commentsexpression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain all comments. const Comments = await app.ActiveDocument.Comments; }
Method
ActiveDocument.Comments.Add()
The Add() method adds comments.
Only JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Comments.Add(Range, Text)expression: the document type application object.
Parameters
Property
Type
Required
Description
Range
Object
Yes
The text area for comments.
Text
String
Yes
The content of the comment.
Description of Range
Property
Type
Required
Description
Start
Number
Yes
The start position of the range to which you want to add the comment.
End
Number
Yes
Set the comment's end point.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain all comments. const comments = await app.ActiveDocument.Comments; // Add a comment. await comments.Add({ Range: { Start: 0, End: 9, }, Text: 'Aliyun comment', }); }
ActiveDocument.Comments.DeleteComment()
Deletes the specified comment based on the position.
Only JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Comments.DeleteComment({ Start, Length })expression: the document type application object.
Parameters
Properties
Data type
Required
Description
Start
Number
Yes
The start position of the comment.
Length
Number
Yes
The length of the comment text. Unit: bytes.
Example
//@file=base.docx async function example() { await instance.ready(); const app = instance.Application; // The comment object. const comments = await app.ActiveDocument.Comments; // Add a comment. await comments.Add({ Range: { Start: 0, End: 9, }, Text: 'Comment', }); // Delete a comment. await comments.DeleteComment({ Start: 0, Length: 9, }); }
ActiveDocument.Comments.DeleteCommentById()
To find the ID of a comment, you can retrieve all comments in the document.
Deletes a comment based on its ID.
Only JS-SDK V1.1.19 and later support this feature.
Syntax
expression.ActiveDocument.Comments.DeleteCommentById({ CommentId })expression: an Application object.
Parameters
Property
Data type
Required
Description
CommentId
String
Yes
The ID of the comment. You can obtain all comments (comment IDs included) in the document by calling ActiveDocument.GetComments.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain comments in the document. const comments = await app.ActiveDocument.Comments; // Delete the specified comment. await comments.DeleteCommentById({ CommentId: '1234567890' }); }
ActiveDocument.Comments.GetCommentReferenceText()
The GetCommentReferenceText() method retrieves the reference text of a comment.
Only JS-SDK V1.1.19 and later support this feature.
Syntax
expression.ActiveDocument.Comments.GetCommentReferenceText({ CommentId })expression: an Application object.
Parameters
Property
Type
Required
Description
CommentId
String
Yes
The ID of the comment. You can obtain all comments (comment IDs included) in the document by calling ActiveDocument.GetComments.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain comments in the document. const comments = await app.ActiveDocument.Comments; // Obtain the reference text of the specified comment. await comments.GetCommentReferenceText({ CommentId: '1234567890' }); }
ActiveDocument.Comments.GoToComment()
You can use the GoToComment() method to navigate to a comment.
Only JS-SDK V1.1.19 and later support this feature.
Syntax
expression.ActiveDocument.Comments.GoToComment({ CommentId })expression: an Application object.
Parameters
Property
Type
Required
Description
CommentId
String
Yes
The ID of the comment. You can obtain all comments (comment IDs included) in the document by calling ActiveDocument.GetComments.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain comments in the document. const comments = await app.ActiveDocument.Comments; // Jump to the comment. await comments.GoToComment({ CommentId: '1234567890' }); }
ActiveDocument.Comments.ModifyComment()
You can use the ModifyComment() method to modify a comment.
Only JS-SDK V1.1.19 and later support this feature.
Syntax
expression.ActiveDocument.Comments.ModifyComment({ CommentId, Text })Expression: Document.Type.Application.Object
Parameters
Property
Data type
Required
Description
CommentId
String
Yes
The ID of the comment. You can obtain all comments (comment IDs included) in the document by calling ActiveDocument.GetComments.
Text
String
Yes
The new comment.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain comments in the document. const comments = await app.ActiveDocument.Comments; // Modify the content of the specified comment. await comments.ModifyComment({ CommentId: '1234567890', Text: 'New comment content' }); }
ActiveDocument.Comments.ReplyComment()
You can call the ReplyComment() method to reply to comments.
Only JS-SDK V1.1.14 and later versions support this feature.
Syntax
expression. ActiveDocument.Comments.ReplyComment({ CommentId, Text })expression: the document type application object.
Parameters
Property
Type
Required
Description
CommentId
String
Yes
The ID of the comment to which you want to reply. You can obtain the comments, including CommentId using
ActiveDocument.GetComments.Text
String
Yes
The content of the reply.
Return value
WebOffice V4.2.1 and later support returning comment data.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain all comments in the document. const comments = await app.ActiveDocument.Comments; // Add a comment. await comments.Add({ Range: { CommentId: 0, End: 9, }, Text: 'Aliyun comment', }); // Obtain the first comment. const comments = await WPSOpenApi.Application.ActiveDocument.GetComments(); const firstCommentId = comments[0].commentId; // Reply to the comment. await comments.ReplyComment({ CommentId: firstCommentId, Text: 'Reply to the first comment', }); }