Hi,
I’m using Aspose Words for Java 17.8.
I have some problems with comparing documents.
I want to change a document (replace text) and then compare to another document.
For example I have the following code (it’s only to demonstrate the behaviour):
@Test
public void test() throws Exception {
Document template = new Document("<path to document>\\template.docx");
Document expected = new Document("<path to document>\\expected.docx");
Run run = (Run)template.getChild(NodeType.RUN, 1, true);
DocumentBuilder builder = new DocumentBuilder(template);
builder.moveTo(run);
builder.insertHtml("test <b>bold</b>", true);
run.remove();
template.compare(expected, "user", new Date());
Assert.assertFalse(template.hasRevisions());
}
Test.zip (16.9 KB)
The document “template.docx” contains only one word (run), for example “replace”. The given HTML string is added at this run (“replace”). Then the run is removed from the document. The document contains the string “test bold” where the text “bold” is bold.
The document “expected.docx” contains the string “test bold” where the text “bold” is bold.
The test case fails because there are revisions in the document. When I open the saved document with the revisions in Microsoft Word there are no changes and the result is expected.
The OOXML of the changed document with the revisions:
<w:p>
...
<w:r>
<w:rPr>
<w:b/>
<w:bCs/>
<w:rPrChange w:id="1" w:author="user" w:date="2017-09-05T11:02:20Z">
<w:rPr>
<w:b/>
<w:bCs/>
</w:rPr>
</w:rPrChange>
</w:rPr>
<w:t>bold</w:t>
</w:r>
</w:p>
The node “w:rPr” within the node “w:rPrChange” does not differ from the original node.
The failure only appears when using the method “insertHtml(String, boolean)”.
The following test does not fail:
@Test
public void test2() throws Exception {
Document template = new Document("<path to document>\\template.docx");
Document expected = new Document("<path to document>\\expected.docx");
Run run = (Run)template.getChild(NodeType.RUN, 1, true);
DocumentBuilder builder = new DocumentBuilder(template);
builder.moveTo(run);
builder.write("test ");
builder.setBold(true);
builder.write("bold");
run.remove();
template.compare(expected, "user", new Date());
Assert.assertFalse(template.hasRevisions());
}
Is there a problem with the method “insertHtml(String, boolean)”?
Kind regards,
Ingo