目标:我需要从.ppt文件中的表中提取文本(列名称为姓名、地址、联系电话、电子邮件等)。为此,我遵循了这种方法:
我将.ppt文件转换为pdf,然后使用PDFminer从pdf中提取数据。从 pdf 中提取的文本不使用任何分隔符分隔。因此,很难区分表中的名称和其他字段。
我正在研究的可能解决方案:
我被困在将文件格式从 .ppt 转换为 .pptx 的第一步。 我找不到任何在 python 中将 .ppt 文件格式转换为 .pptx 格式的解决方案。
我创建了这段代码希望这对您有用:
import win32com.client
PptApp = win32com.client.Dispatch("Powerpoint.Application")
PptApp.Visible = True
PPtPresentation = PptApp.Presentations.Open(r'D:\ppt\sample.ppt')
PPtPresentation.SaveAs(r'D:\ppt\final.pptx', 24)
PPtPresentation.close()
PptApp.Quit()
对于 MacOS Homebrew 用户:安装 Apache Tika (
brew install tika
)
命令行界面的工作方式如下:
tika --text something.ppt > something.txt
并在 python 脚本中使用它:
import os
os.system("tika --text temp.ppt > temp.txt")
你一定能做到,这是我迄今为止唯一的解决方案。
import os
os.system("libreoffice --headless --invisible --convert-to pptx *.ppt")
在 anaconda 3 上完美工作
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_ppt\\"))
save_as_pptx(path)