Accept or Reject Revisions

GroupDocs.Comparison for Python via .NET can extract Word track-change revisions from a DOCX file, let you accept or reject each one, and save the updated document.

To process revisions, follow these steps:

  1. Instantiate a RevisionHandler and provide the source document path or stream.
  2. Call get_revisions() to retrieve the list of revisions.
  3. For each revision, set action to RevisionAction.ACCEPT or RevisionAction.REJECT.
  4. Call apply_revision_changes() with the result file path and ApplyRevisionOptions containing the decisions.

Example 1: Accept insertions and reject other revisions (file)

from groupdocs.comparison.words.revision import RevisionHandler, RevisionAction, ApplyRevisionOptions

def accept_or_reject_revisions():
    with RevisionHandler("./Document_with_revision.docx") as revision_handler:
        revisions = revision_handler.get_revisions()
        for revision in revisions:
            if revision.type == "Insertion":
                revision.action = RevisionAction.ACCEPT
            else:
                revision.action = RevisionAction.REJECT

        options = ApplyRevisionOptions()
        options.changes = revisions
        revision_handler.apply_revision_changes("./result.docx", options)

if __name__ == "__main__":
    accept_or_reject_revisions()

Document_with_revision.docx is the source file used in this example. Click here to download it.

Binary file (DOCX, 21 KB)

Download full output

Example 2: Process revisions from a stream

from groupdocs.comparison.words.revision import RevisionHandler, RevisionAction, ApplyRevisionOptions

def accept_or_reject_revisions_stream():
    with open("./Document_with_revision.docx", "rb") as source_stream:
        with RevisionHandler(source_stream) as revision_handler:
            revisions = revision_handler.get_revisions()
            for revision in revisions:
                if revision.type == "Insertion":
                    revision.action = RevisionAction.ACCEPT

            options = ApplyRevisionOptions()
            options.changes = revisions
            revision_handler.apply_revision_changes("./result.docx", options)

if __name__ == "__main__":
    accept_or_reject_revisions_stream()

Document_with_revision.docx is the source file used in this example. Click here to download it.

Binary file (DOCX, 21 KB)

Download full output

Example 3: Accept or reject all revisions at once

To apply a single decision to every revision in the document, set common_handler on ApplyRevisionOptions:

from groupdocs.comparison.words.revision import RevisionHandler, RevisionAction, ApplyRevisionOptions

def accept_all_revisions():
    with RevisionHandler("./Document_with_revision.docx") as revision_handler:
        options = ApplyRevisionOptions()
        options.common_handler = RevisionAction.ACCEPT
        revision_handler.apply_revision_changes("./result.docx", options)

if __name__ == "__main__":
    accept_all_revisions()

Document_with_revision.docx is the source file used in this example. Click here to download it.

Binary file (DOCX, 21 KB)

Download full output

Result of revision processing

Source fileResult file
Close
Loading

Analyzing your prompt, please hold on...

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