Skip to main content

AddComment

Adds a comment to the current range.

Syntax

expression.AddComment(sText, sAuthor, sUserId);

expression - A variable that represents a ApiRange class.

Parameters

NameRequired/OptionalData typeDefaultDescription
sTextRequiredstringThe comment text.
sAuthorOptionalstringThe author's name.
sUserIdOptionalstringThe user ID of the comment author.

Returns

ApiComment

Example

Attach a reviewer note to a selected portion of text in a document.

// How do I add a comment with an author name to a text selection in a document?

// Annotate a passage with feedback and an author attribution in a document.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
paragraph.AddText("Document");
let range = doc.GetRange(0, 7);
range.AddText("ONLYOFFICE ", "before");
range.AddText(" Builder", "after");
range.AddComment("comment", "John Smith");