Quantcast
Channel: Open XML Format SDK forum
Viewing all articles
Browse latest Browse all 1288

Add Comment in to selected Text in Word Document Using OpenXML c#

$
0
0

I need to use OpenXML to add comments in to a word document. I need to add a comment to a location or word(or multiple words). Normally in a word document openxml return those text as run elements. But the words which I wanted to add a comment is coming with different run elements. So I couldn't add a comment in to the document words which i actually wanted. It means that I couldn't add specificCommentRangeStart and CommentRangeEnd objects.

My current implementation is as below.

foreach(var paragraph in document.MainDocumentPart.Document.Descendants<DocumentFormat.OpenXml.Wordprocessing.Paragraph>()){foreach(var run in paragraph.Elements<Run>()){var item = run.Elements<Text>().FirstOrDefault(b => b.Text.Trim()=="My words selection to add comment");if(item !=null){
                                    run.InsertBefore(newCommentRangeStart(){Id= id }, item);var cmtEnd = run.InsertAfter(newCommentRangeEnd(){Id= id }, item);
                                    run.InsertAfter(newRun(newCommentReference(){Id= id }), cmtEnd);}}}


Viewing all articles
Browse latest Browse all 1288

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>