It is necessary to replace the text received from the bookmark.
I find a bookmark through var range = document.GetBookmarkRange("Recipient");
I need to replace the text in range with my test. addText - can add text before or after Delete - deletes everything, but addText does not insert anything.
This is the problem of migrating an existing system that uses MS Office to create documents using templates (insertion locations are defined by bookmarks) to a subsystem for creating documents via DocumentBuilder (using already existing templates).
Therefore, the question was asked specifically about bookmarks.
SearchAndReplace - has both its pros and cons. You can replace several identical “replacement templates” with one value, but this “replacement template” must be unique so that it does not accidentally occur in the general text.
On the other hand, the bookmark can be “stretched” to the standard text by default, and when generating a document, the text will be skipped and the text will be valid
Probably the situation is related to the fact that text which you want to change is stored in the Comment object. Probably this example will be useful:
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
oParagraph.AddText("This is just a sample text");
Api.AddComment(oParagraph, "comment", "John Smith");
var aComments = oDocument.GetAllComments();
aComments[0].SetText("new comment");
aComments[0].SetText('replace text')
aComments[0].SetText('and again')