输入文件

import com.spire.doc.Document;import com.spire.doc.documents.CommentMark;import com.spire.doc.documents.Paragraph;import com.spire.doc.fields.Comment;import com.spire.doc.fields.TextRange;public class GetMarkedTextOfSpecificComment { public static void main(String[] args){ //Load the Word document Document doc = new Document(); doc.loadFromFile("Input.docx"); //Get the first comment in the document Comment comment = doc.getComments().get(0); //Get the start mark and end mark of the comment Paragraph para = comment.getOwnerParagraph(); CommentMark start = comment.getCommentMarkStart(); CommentMark end = comment.getCommentMarkEnd(); //Get the index of the comment start mark and the comment end mark int indexOfStart = para.getChildObjects().indexOf(start); int indexOfEnd = para.getChildObjects().indexOf(end); String markedText = ""; //Get the marked text between the comment start mark and comment end mark according to the index for (int i = indexOfStart + 1; i < indexOfEnd; i++) { if (para.getChildObjects().get(i) instanceof TextRange) { TextRange range = (TextRange) para.getChildObjects().get(i); markedText += range.getText(); } } //Print out the marked text System.out.println(markedText); } }
输出结果

Spire.Doc for Java 4.7.0已发布。该版本增强了转换Word/RTF到PDF,以及转换HTML到Word的功能。此外,本次更新还修复了加载和保存Word文档等时出现的问题。
整合所有格式API处理套包Spire.office for Java正在 火热销售中!联系客服立马1分钟了解全部咨询!
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!