Hello,
Can you please suggest how can compare two doc file and get the list of changes in both report.
To compare two DOC files and obtain a list of changes, you can use the Aspose.Words library. Below is a sample code snippet demonstrating how to perform the comparison and retrieve the revisions:
C# Example
using System;
using Aspose.Words;
using Aspose.Words.Comparing;
class Program
{
static void Main()
{
// Load the documents to compare
Document docA = new Document("path/to/DocumentA.docx");
Document docB = new Document("path/to/DocumentB.docx");
// Compare the documents
docA.Compare(docB, "User", DateTime.Now);
// Check if there are any revisions
if (docA.Revisions.Count > 0)
{
Console.WriteLine("Changes found:");
foreach (Revision revision in docA.Revisions)
{
Console.WriteLine($"Type: {revision.RevisionType}");
Console.WriteLine($"Author: {revision.Author}");
Console.WriteLine($"Date: {revision.DateTime}");
Console.WriteLine($"Revision text: {revision.ParentNode.ToString(SaveFormat.Text)}");
}
}
else
{
Console.WriteLine("Documents are equal.");
}
}
}
Java Example
import com.aspose.words.*;
import java.util.Date;
public class CompareDocuments {
public static void main(String[] args) throws Exception {
// Load the documents to compare
Document docA = new Document("path/to/DocumentA.docx");
Document docB = new Document("path/to/DocumentB.docx");
// Compare the documents
docA.compare(docB, "User", new Date());
// Check if there are any revisions
if (docA.getRevisions().getCount() > 0) {
System.out.println("Changes found:");
for (Revision revision : docA.getRevisions()) {
System.out.println("Type: " + revision.getRevisionType());
System.out.println("Author: " + revision.getAuthor());
System.out.println("Date: " + revision.getDateTime());
System.out.println("Revision text: " + revision.getParentNode().toString(SaveFormat.Text));
}
} else {
System.out.println("Documents are equal.");
}
}
}
Explanation
- The
Compare
method is used to compare two documents. The first document (docA
) will contain the changes as revisions after the comparison. - You can iterate through the
Revisions
collection of the first document to get details about each change, including the type of change, author, date, and the text that was modified.
This approach allows you to effectively compare two DOC files and generate a report of the changes made.
For more detailed examples and options, you can refer to the Aspose documentation and GitHub examples.
@RiteshAML10 Please see our documentation to lean more about document comparison feature:
https://docs.aspose.com/words/net/compare-documents/