Search code examples
pythonms-wordasposeaspose.words

How to match number of Aspose revisions with Word doc revisions


When I open a Word document with revisions, I observe a certain number of revisions, for instance, 4 revisions (1 insertion and 3 formatting). However, when I utilize Aspose.Word in Python to extract the revisions from the document, I obtain a different count, in this case, 12 revisions (2 insertions and 10 formatting). How can I handle these revisions programmatically to ensure that I end up with the same 4 revisions as observed in the document?

doc = aw.Document(word_doc)
revisions_count = doc.revisions.count

enter image description here


Solution

  • You can access revisions in the document using Document.revisions collection. But in MS Word revisions usually are grouped. So to access revisions in the same way as they are represented in MS Word, it is more convenient to use RevisionGroup. For example see the following code:

    doc = aw.Document("C:\\Temp\\in.docx")
    for group in doc.revisions.groups:
        print(f"Revision author: {group.author};\r\nRevision type: {group.revision_type}\r\nRevision text: {group.text}")
        print("=============================")