Super BUFF Meatballs
Super BUFF Meatballs

Reputation: 225

Covert a PowerPoint PPT File to PPTX using Python 3

I want to convert a file that was saved in the ppt file type to the pptx file type using python. I found "python-pptx" and was planning on using it to save the files, however this was not possible due to the error:

Package not found at 'FileName.ppt'

I discovered another post (Convert ppt file to pptx in Python) which did not help me at all. I assume it is because my Python version might be too high. (3.9) After reading up on getting the win32com.client to work and installing multiple pip and pip3 commands, it is still not working.

My current, non-working code attempt:

from pptx import *

prs = Presentation("FileName.ppt")
prs.save("FileName.pptx")

How can I convert this .ppt file to the .pptx format?

Upvotes: 0

Views: 1731

Answers (3)

Andrey Potapov
Andrey Potapov

Reputation: 67

You can use Aspose.Slides for .NET and Python.NET package for converting PPT to PPTX as shown below:

import clr
clr.AddReference('Aspose.Slides')
from Aspose.Slides import Presentation
from Aspose.Slides.Export import SaveFormat


# Instantiate a Presentation object that represents a PPT file
presentation = Presentation("presentation.ppt")

# Save the presentation as PPTX
presentation.Save("presentation.pptx", SaveFormat.Pptx)

Our web applications use our libraries and you can see conversion results here.

Disclaimer: I work at Aspose.

Upvotes: 2

leekyounghwa
leekyounghwa

Reputation: 26

This works perfectly on anaconda 3 + jupyter notebook

from glob import glob
import re
import os
import win32com.client

paths = glob('C:\\yourfilePath\\*.ppt', recursive=True)

def save_as_pptx(path):
    PptApp = win32com.client.Dispatch("Powerpoint.Application")
    PptApp.Visible = True
    PPtPresentation = PptApp.Presentations.Open(path)
    PPtPresentation.SaveAs(path+'x', 24)
    PPtPresentation.close()
    PptApp.Quit()
    
for path in paths:
    print(path.replace("\\yourfile\\", "\\yourfile_pptx\\"))
    save_as_pptx(path)

Upvotes: 0

Martin Packer
Martin Packer

Reputation: 763

I doubt python-pptx can parse a .ppt file. (It's a completely different file format.) You're better off automating PowerPoint itself - somehow - to read one and write the other.

The "somehow" depends on the platform you're running on - and the automation capabilities available to you.

Upvotes: 1

Related Questions