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);

}

}

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐