Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active December 13, 2023 11:49
Show Gist options
  • Save aspose-com-gists/e86343227ed63b2f0739c02b6a8c2f74 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/e86343227ed63b2f0739c02b6a8c2f74 to your computer and use it in GitHub Desktop.
Compare Two Word Documents using Python
import aspose.words as aw
from datetime import date
# load first document
doc = aw.Document("calibre.docx")
# load second document
doc2 = aw.Document("calibre2.docx")
# set additional options
options = aw.comparing.CompareOptions()
options.ignore_formatting = True
options.ignore_headers_and_footers = True
options.ignore_case_changes = True
options.ignore_tables = True
options.ignore_fields = True
options.ignore_comments = True
options.ignore_textboxes = True
options.ignore_footnotes = True
# compare documents
doc.compare(doc2, "user", date.today(), options)
# save the document to get the revisions
if (doc.revisions.count > 0):
doc.save("compared.docx")
else:
print("Documents are equal")
import aspose.words as aw
from datetime import date
# load first document
doc = aw.Document("calibre.docx")
# load second document
doc2 = aw.Document("calibre2.docx")
# compare documents
doc.compare(doc2, "user", date.today())
# save the document to get the revisions
if (doc.revisions.count > 0):
doc.save("compared.docx")
else:
print("Documents are equal")
@jeden4
Copy link

jeden4 commented Jul 7, 2022

Keep getting an error that the date is not defined. i added "import time" but still doesn't work

@usman-aziz
Copy link

@jeden4 ,
Make sure you have added the following import:

from datetime import date

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment