Adding Nodes to a Comment Node using DocumentWriter

Hi Guys,
I am using the Document Writer methods to transform our XML into a Word docx which is doing what we need.
Recently I have been asked to support word comments which have been added to our Word to XML process (Comment Replies and Comment Done not supported yet).

My question is that can Document Writer be aware that it is writing/creating a Comment node so that inserting a paragraph will target the comment?

If this is not possible then is the only way to achieve the various Comment Nodes is the long handed way of node create and append?

Cheers
Jan

Hi Jan,

Thanks for your inquiry. Yes, comment’s reply is not supported in Aspose.Words at the moment. To insert comment in the document, you need to create object of Comment class and insert that object into document using DocumentBuilder. DocumentBuilder does not keep track of inserted nodes. However, using following code example you can keep track of Comment objects.

Following code example shows how to add a comment to a paragraph in the document. Hope this helps you.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("Some text is added.");
Comment comment = new Comment(doc, "Amy Lee", "AL", DateTime.Today);
builder.CurrentParagraph.AppendChild(comment);
comment.Paragraphs.Add(new Paragraph(doc));
comment.FirstParagraph.Runs.Add(new Run(doc, "Comment text."));

Moreover, DocumentBuilder is a powerful class that is associated with a Document and allows dynamic document building from scratch or the addition of new elements to an existing document. It provides methods to insert text, paragraphs, lists, tables, images and other contents, specification of font, paragraph, and section formatting, and other things. Using DocumentBuilder is somewhat similar in concept to using the StringBuilder class of the .NET Framework.

Please let us know if you have any more queries.

Hi,
Thanks for your reply.
Having developed a ton of code that uses DocWriter I was hoping that I had missed a start/end comment so that i can simply write anything as children of the comment using my doc writer classes.
So a simple Paragraph that has several Runs and Field copes etc would just be writing via Docwriter to the main or table cell or comment with me needing to duplicate.

I have come up with a work around now.
I create a temporary Docwriter class for each comment and switch which active docwriter is in force. This means that I am running my code without knowing where I am writing it; LOL
I then use import to copy whatever was written to add to my comment node.

Works well…

Thanks Again
Jan

Hi Jan,

Thanks for your inquiry. Please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.