Get List of Changes
Leave feedback
On this page
GroupDocs.Comparison for Python via .NET populates an internal change list during the comparison. After calling compare(), retrieve the changes via get_changes().
from groupdocs.comparison import Comparer
def get_list_of_changes():
with Comparer("./source.docx") as comparer:
comparer.add("./target.docx")
comparer.compare()
for change in comparer.get_changes():
print(f"Type: {change.type}, Page: {change.page_info.page_number}, Id: {change.id}, Text: {change.text}")
if __name__ == "__main__":
get_list_of_changes()
source.docx is the source file used in this example. Click here to download it.
target.docx is the target file used in this example. Click here to download it.
Type: 2, Page: 1, Id: 0, Text: Cool
Type: 2, Page: 1, Id: 1, Text:
Type: 3, Page: 1, Id: 2, Text: test
Type: 2, Page: 1, Id: 3, Text: signatures
Type: 2, Page: 1, Id: 4, Text: Our
Type: 2, Page: 1, Id: 5, Text: char[
Type: 2, Page: 1, Id: 6, Text: 255]
Type: 2, Page: 1, Id: 7, Text:
Type: 3, Page: 1, Id: 8, Text:
Use case: build a custom report UI listing every difference with pagination info.
from groupdocs.comparison import Comparer
def get_list_of_changes_stream():
with open("./source.docx", "rb") as source_stream, \
open("./target.docx", "rb") as target_stream:
with Comparer(source_stream) as comparer:
comparer.add(target_stream)
comparer.compare()
for change in comparer.get_changes():
print(f"Type: {change.type}, Page: {change.page_info.page_number}, Id: {change.id}, Text: {change.text}")
if __name__ == "__main__":
get_list_of_changes_stream()
source.docx is the source file used in this example. Click here to download it.
Type: 2, Page: 1, Id: 0, Text: Cool
Type: 2, Page: 1, Id: 1, Text:
Type: 3, Page: 1, Id: 2, Text: test
Type: 2, Page: 1, Id: 3, Text: signatures
Type: 2, Page: 1, Id: 4, Text: Our
Type: 2, Page: 1, Id: 5, Text: char[
Type: 2, Page: 1, Id: 6, Text: 255]
Type: 2, Page: 1, Id: 7, Text:
Type: 3, Page: 1, Id: 8, Text:
Use case: integrate diff extraction into services that operate on file streams.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.