Page 1 of 1

scan Comments in docx4j

PostPosted: Sun Apr 14, 2013 9:35 pm
by eltayeb
i want to get the value of the comment as i get these 3 objects

org.docx4j.wml.CommentRangeStart
org.docx4j.wml.CommentRangeEnd
org.docx4j.wml.R.CommentReference

but so i from these objects i can get the text commented but i want to know the comment value

Re: scan Comments in docx4j

PostPosted: Sun Apr 14, 2013 11:23 pm
by eltayeb
i get method to get the comments


this is sample to get comment text of first comment
Code: Select all
CommentsPart cmt =  wordMLPackage.getMainDocumentPart().getCommentsPart();
List<org.docx4j.wml.Comments.Comment> lst = cmt.getJaxbElement().getComment();
lst.get(0).getEGBlockLevelElts().get(0)

Re: scan Comments in docx4j

PostPosted: Mon Apr 15, 2013 12:09 pm
by jason
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
      <w:commentRangeStart w:id="0"/>
      <w:r>
        <w:t xml:space="preserve">mouse </w:t>
      </w:r>
      <w:commentRangeEnd w:id="0"/>
      <w:r >
        <w:rPr>
          <w:rStyle w:val="CommentReference"/>
        </w:rPr>
        <w:commentReference w:id="0"/>
      </w:r>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


For a given comment, the ID is present on each of w:commentRangeStart, w:commentRangeEnd, w:commentReference

Use that ID to get the corresponding comment from the comments part.

CommentsPart doesn't currently have a method getCommentByID, so you have to iterate through them yourself.

If you'd like to contrib that simple method, I'd be happy to add it to docx4j,