我是靠谱客的博主 自觉小猫咪,这篇文章主要介绍使用python将ppt文件批量转为pptx、批量提取ppt中的文字保存,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os from pptx import Presentation from docx import Document import os.path import win32com.client class PPT2Word(object): """将filepath对应的pptx文件中的文字提取,并保存为同名docx文档""" def __init__(self, filepath): self.wordfile = Document() self.filepath = filepath self.pptx = Presentation(self.filepath) def main(self): for slide in self.pptx.slides: for shape in slide.shapes: if shape.has_text_frame: text_frame = shape.text_frame for paragraph in text_frame.paragraphs: self.wordfile.add_paragraph(paragraph.text) save_path = self.filepath.replace(".pptx", ".docx").replace(".ppt", ".doc") self.wordfile.save(save_path) """ 新建目录,放入本文件、各个文件夹(文件夹内为待转换的若干ppt文件) """ if __name__ == "__main__": powerpoint = win32com.client.Dispatch('PowerPoint.Application') win32com.client.gencache.EnsureDispatch('PowerPoint.Application') powerpoint.Visible = 1 dir_list = os.listdir() dir_list.remove("select_word4ppt.py") if ".idea" in dir_list: dir_list.remove(".idea") print(dir_list) for dir in dir_list: ppt_list = os.listdir(dir) print(ppt_list) for ppt in ppt_list: # 如果是ppt文件,先另存为pptx文件 if ppt[-3:] == "ppt": subPath = os.path.abspath(r"{}{}".format(dir, ppt)) # 此处要为绝对路径 ppt1 = powerpoint.Presentations.Open(subPath) ppt1.SaveAs(subPath[:-4] + '.pptx') ppt = ppt + 'x' print(ppt) # 提取pptx文件中的文字并保存 ppt2word = PPT2Word(filepath=r"{}{}".format(dir, ppt)) ppt2word.main()

最后

以上就是自觉小猫咪最近收集整理的关于使用python将ppt文件批量转为pptx、批量提取ppt中的文字保存的全部内容,更多相关使用python将ppt文件批量转为pptx、批量提取ppt中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(117)

评论列表共有 0 条评论

立即
投稿
返回
顶部