国产Word格式处理控件Spire.Doc功能演示:在 Java 中获取 Word 中特定注释的标记文本

在本文中,我们将向您展示如何使用 Spire.Doc for Java 在 Word 中获取特定评论的标记文本。

Spire.Doc for Java 是一款专业的Java Word组件,开发人员使用它可以轻松地将Word文档创建、读取、编辑、转换和打印等功能集成到自己的Java应用程序中。

在本文中,我们将向您展示如何使用 Spire.Doc for Java 在 Word 中获取特定评论的标记文本。 点击此处下载最新版测试

输入文件

国产Word格式处理控件Spire.Doc功能演示:在 Java 中获取 Word 中特定注释的标记文本
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); } }

输出结果

国产Word格式处理控件Spire.Doc功能演示:在 Java 中获取 Word 中特定注释的标记文本


Spire.Doc for Java 4.7.0已发布。该版本增强了转换Word/RTF到PDF,以及转换HTML到Word的功能。此外,本次更新还修复了加载和保存Word文档等时出现的问题。

整合所有格式API处理套包Spire.office for Java正在网火热销售中!联系客服立马1分钟了解全部咨询!

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年6月19日
下一篇 2021年6月19日

相关推荐

发表回复

登录后才能评论