Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open ppt file using Python

Tags:

python

I want to open a ppt file using Python on linux, (like python open a .txt file). I know win32com, but I am working on linux. So, What do I need to do?

like image 727
MarshalSHI Avatar asked Mar 07 '26 11:03

MarshalSHI


2 Answers

python-pptx can open recent Powerpoint versions on Linux. They even provide an example for extracting all text from slides in their Getting started guide.

Here's the code (from the Getting Started guide)

from pptx import Presentation

prs = Presentation(path_to_presentation)

# text_runs will be populated with a list of strings,
# one for each text run in presentation
text_runs = []

for slide in prs.slides:
    for shape in slide.shapes:
        if not shape.has_textframe:
            continue
        for paragraph in shape.textframe.paragraphs:
            for run in paragraph.runs:
                text_runs.append(run.text)
like image 140
bytesinflight Avatar answered Mar 09 '26 00:03

bytesinflight


If you are on Linux, what office software are you referring to. OpenOffice (headless) can be interfaced using python on Linux. Here is a nice example https://github.com/jledoux/FRIEDA

like image 41
dskrad Avatar answered Mar 09 '26 02:03

dskrad