We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Add @mentions in comments

Hello, Office online allows to @mention users in the comments. What is the preferred way to @mention users in Comments using Aspose.
Comment.setText(“Can we @mention here”) ?

@kml2020 Could you please attach a sample document with @mention in comments? We will check how @mentions are actually written into the document and provide you more information.
By the way, I cannot see such feature in desktop MS Word so I suspect this is a feature of Office Online only.

@alexey.noskov, Thank you for helping look into this. I am attached the sample document to this thread.
AtMentions Sample.docx (12.1 KB)

The feature is through online 365. However, once an document is edited online our requirement is it can be circulated and Users can work on it who use Offline Word as well.

@kml2020 Thank you for additional information. Mentions in the comment are inserted as a simple hyperlink. You can easily achieve this using DocumentBuilder. For example, see the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("This is some text");

// Create a comment and range.
Comment comment = new Comment(doc);
// Add a pragraph into the comment.
comment.AppendChild(new Paragraph(doc));
// Move DocumentBuilder cursor inside the comment
builder.MoveTo(comment.FirstParagraph);
// Insert content.
builder.Write("This comment has mention: ");
// Insert hyperlink
builder.Font.StyleIdentifier = StyleIdentifier.Hyperlink;
builder.InsertHyperlink("@test user", "mailto:test.user@test.com", false);
builder.Font.ClearFormatting();
// and some text after hyperlink
builder.Write(" some text after mentions");

builder.MoveToDocumentEnd();
builder.InsertNode(comment);

doc.Save(@"C:\Temp\out.docx");

Hello @alexey.noskov, Awesome !
Had a question about using document builder though. In case of heavy load ( several operations adding new comments ), is the document builder a resource intensive option as compared to the simply setting the comment text using comment.setText(). In other words what is the cost of using document builder ?

@kml2020 There will not be any performance issues. Both methods does the same - create a Paragraph and put Run for textual content. But DocumentBuilder simplifies the most common document building tasks.

@alexey.noskov, is it safe to have multiple builders on a document, likely it may create conflict ?

Document doc = new Document();
DocumentBuilder builder1 = new DocumentBuilder(doc);
DocumentBuilder builder2 = new DocumentBuilder(doc);

@kml2020 Yes, it is safe to have multiple DocumentBuilder instances on the same Document.

Thank you for the confirmation, @alexey.noskov. This is helpful !

1 Like