首页 > 解决方案 > 如何使用 Python 将 PPT 文件保存为 PPTX 文件?或如何使用 python-pptx 准备 PPT 文件?

问题描述

我试过下面的代码,但我无法将PPT文件保存为PPTX文件。

from pptx import Presentation
import os
import glob

for each_file in glob.glob("C:/Users/Downloads/*.ppt"):
    #prs = Presentation(each_file)
    fname=os.path.basename(each_file)
    f = open(each_file)
    f.save(fname[:-4]+'.pptx')
    f.close()```


***Error***: `AttributeError: '_io.TextIOWrapper' object has no attribute 'save'`


标签: python-pptx

解决方案


似乎.ppt不支持文件。

以下行(.ppt files from PowerPoint 2003 and earlier won’t work)位于python-pptx文档的第 13 页:https ://readthedocs.org/projects/python-pptx/downloads/pdf/latest/


推荐阅读