Hi, I have one comment list which includes replies also. And I’m adding those to our document, but also I want to highlight on which word comment is added for that I am using the following lines.
CommentRangeStart commentRangeStart = new CommentRangeStart(sourceDocument, comment.Id);
CommentRangeEnd commentRangeEnd = new CommentRangeEnd(sourceDocument, comment.Id);
commentRun.ParentNode.InsertBefore(commentRangeStart, commentRun);
commentRun.ParentNode.InsertAfter(commentRangeEnd, commentRun);
commentRangeEnd.ParentNode.InsertAfter(comment, commentRangeEnd)
with this code im getting output(comments.docx file name in attached zip) in which replies are also treated as separate comment and without this code I’m getting the document without highlighting but with proper nested replies
But my required output is(file attached in zip names requiredoutput.docx) I want to highlight the commented word and with proper nested replies.Input and Required Output (2).zip (72.2 KB)
@Amrinder_Singh Unfortunately your output were not attached to the topic. Could you please try to attach it again?
Input and Required Output (2).zip (72.2 KB)
Sorry i forgot to attach this
@Amrinder_Singh Thank you for additional information. We will investigate the problem and provide you more information.
@Amrinder_Singh Please try to move comment replies along with the main comment. Use could use the following code:
CommentRangeStart commentRangeStart = new CommentRangeStart(sourceDocument, comment.Id);
CommentRangeEnd commentRangeEnd = new CommentRangeEnd(sourceDocument, comment.Id);
commentRun.ParentNode.InsertBefore(commentRangeStart, commentRun);
commentRun.ParentNode.InsertAfter(commentRangeEnd, commentRun);
commentRangeEnd.ParentNode.InsertAfter(comment, commentRangeEnd);
// Move replies along with the main comment.
var repliesToMove = comment.Replies.ToList();
repliesToMove.Reverse();
repliesToMove.ForEach(reply => comment.ParentNode.InsertAfter(reply, comment));
Thanks @Konstantin.Kornilov I will check that also
But another issue i am having i have html string like following
<p>To insert a new paragraph into the document , in fact, you need to insert a paragraph break character into it. Document Builder inserts not only a string of text into the document, but also adds a paragraph break.</p><p>The current font formatting is also specified by the Font property, and the current paragraph formatting is determine d by the Paragraph property. In the next section, we will go into more detail about paragraph formatting. </p><p>The following code example shows how to insert a paragraph into a document:</p><ul><li>This is the first element </li><li>Second Element</li><li>Third Element</li><li>Fourth Element</li></ul><ol><li><strong>Current Paragraph</strong> </li><li><i>Next Paragraph</i></li><li>Third Paragraph</li><li>Fourth Paragraph</li><li>Fifth Paragraph</li></ol><p> </p><table style="height: 100%; width: 100%;"><tbody><tr><td>Sno</td><td>Rank</td><td>Active</td></tr><tr><td>1.</td><td>1</td><td>Yes</td></tr><tr><td>2.</td><td>2</td><td>Yes</td></tr></tbody></table></figure><p> </p><p>This is the link <a href="google.com">google.com</a> ok got it</p>
But i am splitting this html string in parts (in other way im creating list divding html sting to multiple parts based on my requirements)
e.g
<p>To insert a new paragraph into the document , in fact, you need to insert a paragraph break character into it
When i do builder.InsertHtml(myString[0]) it is automatically closing that. I understand this method supposed to do that but is there anyway i can stop from this to happend?
I cannot user builder.Write(myString[0]) coz i dont need html tags to come in my document.
@Amrinder_Singh Unfortunately it is not possible to insert html by parts as you are trying. DocumentBuilder.InsertHtml
treats the html string as a complete html block and closes all unclosed tags. You should consider the tags when splitting html string.
Thank @Konstantin.Kornilov
Is there any other way available through which i can fulfill my requirement?
@Amrinder_Singh You could try to insert/load your HTML string into a temporary document and copy content from it into the target document. This way the HTML tags will be processed by Aspose.Words and you should work with Aspose.Words DOM objects instead.
@Konstantin.Kornilov Won’t be then my runs based on which im anchoring the comments will be lost?
@Amrinder_Singh Sorry, I’m not quite understand what do you mean by that. Could you please clarify you question or maybe provide some sample code?
@Konstantin.Kornilov
In the first posted query in this thread I asked for anchoring the comment, which is happening based on the run. the text I have in that run will be highlighted.
Now if i do all that in separate document and again copy the content from temporary Document to my main document and do the buillder.InsertHtml() new runs will be created and old runs based on which im highlighting(anchor my text) will be lost.
@Amrinder_Singh The DocumentBuilder.InsertHtml() method do not remove the content from the underlying document. It only inserts the HTML content into it. So the runs and anchoring comments will not be removed from the document.