该文将详细介绍如何使用spire.doc for java 在java应用程序中为word文档添加,回复及删除批注。
插入word批注
import com.spire.doc.*;
import com.spire.doc.documents.paragraph;
import com.spire.doc.fields.comment;
public class wordcomment{
public static void main(string[] args) throws exception {
string inputfile = "sample.docx";
string outputfile = "out/comment.docx";
//加载需要添加批注的word文档
document document = new document(inputfile);
section section = document.getsections().get(0);
paragraph paragraph = section.getparagraphs().get(0);
//添加批注
comment comment = paragraph.appendcomment("spire.doc for java");
comment.getformat().setauthor("e-iceblue");
comment.getformat().setinitial("cm");
//保存文档
document.savetofile(outputfile, fileformat.docx);
}
}
java 回复word批注
import com.spire.doc.*;
import com.spire.doc.fileformat;
import com.spire.doc.fields.*;
public class wordcomment {
public static void main(string[] args) throws exception {
string inputfile="sample.docx";
string outputfile="out/replaytocomment.docx";
//加载示例文档
document document= new document(inputfile);
comment comment1 = document.getcomments().get(0);
comment replycomment1 = new comment(document);
replycomment1.getformat().setauthor("e-iceblue");
replycomment1.getbody().addparagraph().appendtext("spire.doc for java 回复批注");
//添加批注作为选中批注的回复
comment1.replytocomment(replycomment1);
//保存文档
document.savetofile(outputfile, fileformat.docx);
}
}
删除word已有批注
import com.spire.doc.*;
import com.spire.doc.fileformat;
public class wordcomment {
public static void main(string[] args) throws exception {
string inputfile="sample.docx";
string outputfile="out/deletecomment.docx";
//加载示例文档
document document= new document(inputfile);
//删除第二条批注
document.getcomments().removeat(1);
//保存文档
document.savetofile(outputfile, fileformat.docx);
}
}