Java 添加Word批注(文本、图片)
1、导入方式1:通过官网下载jar包(https://www.e-iceblue.cn/Downloads/Free-Spire-Doc-JAVA.html),并解压。
导入步骤:在程序中新建一个directory目录,并命名(本示例中命名为lib);将控件包lib文件夹下的jar文件(如下图)复制到程序中新建的目录下,鼠标右键点击jar文件,选择”Add as Library”,完成导入。

2、导入方式2:通过Maven仓库导入到Maven项目中,参考导入方法(https://www.e-iceblue.cn/licensing/install-spirepdf-for-java-from-maven-repository.html)
1、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);
}
}
2、批注添加效果:
