DEV Community

E-iceblue Product Family
E-iceblue Product Family

Posted on

1 1

Compare Two Word documents and get the difference reports in Java

It is a time-consuming job when we need to analyzes two Word documents which look similar. Spire.Doc for Java offers a method of doc1.compare(doc2, "Author") to compare the word document and generate a report in track changes to make the difference clearly. As long as you have two separate Word documents, you can compare them in three lines of codes in Java applications.
Firstly, ensure that you are using Spire.Doc for Java V 3.8.8 or above and please check the sample word document as below:
Sample word

import com.spire.doc.Document;

public class CompareWordDocuments {

    public static void main(String[] args)throws Exception  {
        //Create a Document instance
        Document doc1 = new Document();
        //Load the first Word document
        doc1.loadFromFile("Sample.docx");

        //Create a Document instance
        Document doc2 = new Document();
        //Load the second Word document
        doc2.loadFromFile("Sample1.docx");

        //Compare the two Word documents
        doc1.compare(doc2, "E-iceblue");

        //Save the result to file
        doc1.saveToFile("Result.docx");

    }
}
Enter fullscreen mode Exit fullscreen mode

After run the project,we will get the Word document as below:
Output

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more