1

I need to extract comments (made using the Microsoft PowerPoint comment feature) from a series of PowerPoint presentations.

The following link explains how to do it in C#:

https://www.e-iceblue.com/Tutorials/Spire.Presentation/Spire.Presentation-Program-Guide/Comment-and-Note/Extract-comments-from-presentation-slides-and-save-in-txt-file.html

It appears that python-pptx does not have the functionality to read/write comments from PowerPoint:

https://python-pptx.readthedocs.io/en/latest/

If such a feature exists, I can not find it in the documentation above.

Is there any way to do this?

stolbert
  • 61
  • 1
  • 5
  • There is no requirement for any specific package use, If there exists some solution for extracting the comments within python please detail it. Thank you – stolbert Jan 10 '20 at 20:53
  • 1
    It looks like there is a Comment object for PowerPoint VBA [link](https://learn.microsoft.com/en-us/office/vba/api/powerpoint.comment). So you could theoretically use win32com to expose the object and manipulate it, or you could just write a VBA script and trigger it from Python. – K753 Jan 10 '20 at 20:54
  • You didn't say what operating system. The sample code actually doesn't help much because `Comments` hides the detail. What would be interesting would be to dump the XML and find the elements that represent comments. Even more interesting would be to write to the pptx. The latter could almost certainly be done based on python-pptx. – Martin Packer Nov 18 '22 at 07:54
  • I see you've also posted a related question: https://stackoverflow.com/questions/74573080/how-to-edit-comments-in-powerpoint-with-python-python-pptx-or-pywin32 What I'd still like to understand is what the structure of the comments XML is when you renamed a pptx to zip and unzipped it. – Martin Packer Nov 26 '22 at 07:58

3 Answers3

2

I was able to do this by using win32com to access the comment object and manipulate it from there as suggest by K753:

import win32com.client
ppt_dir = 'test.pptx'
ppt_app = win32com.client.GetObject(ppt_dir)

for ppt_slide in ppt_app.Slides:
    for comment in ppt_slide.Comments:
        print(comment.Text)

The following documentation has further details on the comment object:

https://learn.microsoft.com/en-us/office/vba/api/powerpoint.comment

stolbert
  • 61
  • 1
  • 5
0

Referring to this thread, interacting with comments in PowerPoint is not yet possible in python-pptx.

You may be able to request it as a feature through their ReadTheDocs page, though. They recommend that you reach out via the mailing list or issue tracker to suggest a new feature.

Bryan
  • 747
  • 1
  • 7
  • 19
0

And if you need replies to comments you can do this:

for ppt_slide in ppt_app.Slides:
    for comment in ppt_slide.Comments:
        print(comment.Text)
        for reply in comment.Replies:
                print(reply.Text)
A. Jabbitt
  • 41
  • 7