在这里https://docs.aspose.com/words/java/,我没有找到对应的示例。
比如我想这样操作
image.png (6.1 KB)
这是我的文件
docx.docx (11.1 KB)
@humanhuman, 请参考这些文档页面:
- https://docs.aspose.com/words/java/track-changes-in-a-document/
- Document.startTrackRevisionts
- Document.stopTrackRevisions
这是一个如何跟踪删除和新增:
String documentName = "doc.docx";
Document doc = new Document();
DocumentBuilder b = new DocumentBuilder(doc);
b.writeln("First line");
b.writeln("Second line");
doc.save(documentName);
trackAddition(documentName);
trackDeletion(documentName);
static void trackAddition(String documentName) throws Exception {
Document doc = new Document(documentName);
// Track the addition of the third line.
doc.startTrackRevisions("My Name", new Date());
DocumentBuilder b = new DocumentBuilder(doc);
b.moveToDocumentEnd();
b.writeln("Third line");
doc.stopTrackRevisions();
doc.save(documentName);
}
private static void trackDeletion(String documentName) throws Exception {
Document doc = new Document(documentName);
Paragraph secondParagraph = (Paragraph)doc.getChild(NodeType.PARAGRAPH, 1, true);
doc.startTrackRevisions("My Name", new Date());
secondParagraph.remove();
doc.stopTrackRevisions();
doc.save(documentName);
}