java删除word中批注_Java 添加、回复、删除Word批注

class="MsoNormal">在word中,批注是一种常用于对特定文档内容进行注解的方法,起到解释说明、标记指正的作用。本篇文章中,将通过Java程序来演示如何来操作批注,内容要点包括:

1. 添加批注(添加文本、图片到批注)

2. 回复批注

3. 删除批注

?

使用工具:Free Spire.Doc for Java 2.0.0(免费版)

Jar文件导入:

方法1:从官网下载jar包。

导入步骤: 在程序下新建一个directory目录,并命名(本示例中命名为lib);将控件包lib文件夹下的jar(如下图1)复制到程序中新建的目录下。复制jar文件后,鼠标右键点击jar文件,选择”Add as Library”。完成导入(如下图2)。

?

?

图1:

c839dbc7f8cfbd4f15be43c27c50cb62.png

?

图2:

954bfd1edac8b5b4f8af3118cff3527d.png

?

方法2:通过maven导入。参考导入方法。

?

Java代码示例

?

【示例1】添加Word批注

import com.spire.doc.*;

import com.spire.doc.documents.Paragraph;

import com.spire.doc.fields.Comment;

public class AddComment {

public static void main(String[] args) {

//加载测试文档

Document doc = new Document("test.docx");

//获取指定段落

Section sec = doc.getSections().get(0);

Paragraph para= sec.getParagraphs().get(3);

//插入文本到批注

Comment comment = para.appendComment("请在试验中将包含以下特征的实验样本记录在册,并整理好周记录报表,供后续观察取样。");

comment.getFormat().setAuthor("审校组");

//插入图片到批注

comment.getBody().addParagraph().appendPicture("tp.png");

//保存文档

doc.saveToFile("AddComment.docx", FileFormat.Docx_2010);

}

}

?

批注添加效果:

eb47b02a64a357ea0281502e9fa682d0.png

?

【示例2】回复Word批注

import com.spire.doc.*;

import com.spire.doc.fields.Comment;

public class ReplyComment {

public static void main(String[] args) throws Exception{

//加载测试文档

Document doc = new Document("AddComment.docx");

//获取指定批注

Comment comment = doc.getComments().get(0);

//回复批注

Comment relyC= new Comment(doc);

relyC.getFormat().setAuthor("实验组");

relyC.getBody().addParagraph().appendText("已完成。");

comment.replyToComment(relyC);

//保存文档

doc.saveToFile("ReplyComment.docx",FileFormat.Docx_2010);

}

}

?

批注回复结果:

05efc2f0ab9a85f467759490794b3397.png

【示例3】删除Word批注

import com.spire.doc.*;

import com.spire.doc.FileFormat;

public class DeleteComment{

public static void main(String[] args) {

//加载测试文档

Document doc = new Document("AddComment.docx");

//调用方法删除指定批注

doc.getComments().removeAt(0);

//保存文档

doc.saveToFile("DeleteComment",FileFormat.Docx_2010);

}

}

?

运行程序后,批注已被删除。

?

?

(本文完)

92bcfdf6eb84b69ded5f3257aead34e0.png

大小: 56.3 KB

39bbcc3b783e83eac0c51bbee072c4f1.png

大小: 31.1 KB

476ff964805652c016efad64e9fe2ca3.png

大小: 151.4 KB

c0e92ee7cfdf110f6767477e0fc55585.png

大小: 154 KB

查看图片附件

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值