Compare Word Documents

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

@gutzeit,

Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-15854. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Thanks for your reply.

Is there any workaround?

Maybe I could iterate through the revisions. If it is a revision from type “FORMAT_CHANGE” and the parent node is from type “RUN” I could check the revision.
Is it possible to get both fonts - the original and from the revision - so I could check the font by myself?

With the following code I can get the font:

((Run)revision.getParentNode()).getFont()

Is there a way to get the other font from the revision?

Kind regards,
Ingo

@gutzeit,

Thanks for your inquiry. Unfortunately, there is no workaround of this issue. We apologize for your inconvenience.

@gutzeit,

The issues you have found earlier (filed as WORDSNET-15854) have been fixed in this Aspose.Words for .NET 17.10 update and this Aspose.Words for Java 17.10 update.