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?
5 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)
3 Comments
prs = Presentation(path_to_presentation) I am getting the following error File is not a zip file please helptextframe should be text_frame.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
3 Comments
Use odf.opendocument.OpenDocumentPresentation from the odfpy project. This is assuming you are only concerned with recent format files, that are compatible with the OpenDocument standard.
If you have access to OpenOffice, you can use their Python api to read the file.
Comments
You may check Apache Tika because I use it on mac like this
For MacOS Homebrew users: install Apache Tika (brew install tika)
The command-line interface works like this:
tika --text something.ppt > something.txt
And to use it inside python script:
import os
os.system("tika --text temp.ppt > temp.txt")
You will be able to do it and that is the only solution I have so far.
xdg-openshell command.