Accept or reject detected changes

GroupDocs.Comparison for Python via .NET lets you programmatically accept or reject individual changes before producing the final result.

Accept or reject changes (files on disk)

Compare files, update change actions, and apply them to the output.

import groupdocs.comparison as gc

with gc.Comparer("source.docx") as comparer:
    comparer.add("target.docx")
    comparer.compare()
    changes = comparer.get_changes()

    # Example: reject the first change
    if changes:
        changes[0].comparison_action = gc.ComparisonAction.REJECT

    with open("result.docx", "wb") as out_stream:
        comparer.apply_changes(out_stream, gc.ApplyChangeOptions(changes=changes))

🔹 Use case: Remove undesired edits from the final deliverable while keeping approved changes.

The result is as follows:

Accepted changesRejected changes

Accept or reject changes (streams)

Work entirely with streams and persist the merged result.

import groupdocs.comparison as gc

with open("source.docx", "rb") as src, open("target.docx", "rb") as tgt:
    with gc.Comparer(src) as comparer:
        comparer.add(tgt)
        comparer.compare()
        changes = comparer.get_changes()
        if changes:
            changes[0].comparison_action = gc.ComparisonAction.REJECT
        with open("result.docx", "wb") as out_stream:
            comparer.apply_changes(out_stream, gc.ApplyChangeOptions(changes=changes))

🔹 Use case: Integrate approval workflows in services that don’t use local file paths.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.