zoukankan      html  css  js  c++  java
  • WORD添加批注(JAVA)

    import com.spire.doc.*;
    import com.spire.doc.documents.CommentMark;
    import com.spire.doc.documents.CommentMarkType;
    import com.spire.doc.documents.Paragraph;
    import com.spire.doc.documents.TextSelection;
    import com.spire.doc.fields.Comment;

    public class AddCommentToCharacters {
    public static void main(String[] args) {
    //加载测试文档
    Document doc = new Document();
    doc.loadFromFile("test.docx");

    //查找指定字符串
    TextSelection[] selections = doc.findAllString("皱状厚膜", true, false);

    //获取关键字符串所在段落
    Paragraph para = selections[0].getAsOneRange().getOwnerParagraph();
    int index = para.getChildObjects().indexOf(selections[0].getAsOneRange());

    //添加批注ID
    CommentMark start = new CommentMark(doc);
    start.setCommentId(1);
    start.setType(CommentMarkType.Comment_Start);
    CommentMark end = new CommentMark(doc);
    end.setType(CommentMarkType.Comment_End);
    end.setCommentId(1);

    //添加批注内容
    String str = "给指定字符串添加批注";
    Comment comment = new Comment(doc);
    comment.getFormat().setCommentId(1);
    comment.getBody().addParagraph().appendText(str);
    comment.getFormat().setAuthor("作者:");
    comment.getFormat().setInitial("CM");
    para.getChildObjects().insert(index, start);
    para.getChildObjects().insert(index + 1, selections[0].getAsOneRange());
    para.getChildObjects().insert(index + 2,end);
    para.getChildObjects().insert(index + 3, comment);

    //保存文档
    doc.saveToFile("字符串批注.docx",FileFormat.Docx_2013);
    doc.dispose();
    }
    }

  • 相关阅读:
    Linux MySQL的root无法登录数据库ERROR 1045 (28000)
    Linux 命令行初始化MySQL数据库
    Centos6、Centos7防火墙基本操作整理
    文本三剑客之awk
    加密类型、数据加密解密过程以及CA创建
    Centos7启动流程及systemd中Nginx启动配置
    Linux任务计划
    Linux进程管理
    IP地址简介及Linux网络管理工具
    Linux脚本
  • 原文地址:https://www.cnblogs.com/qiu18359243869/p/11806383.html
Copyright © 2011-2022 走看看