This article mainly introduces how to output all the text information in a Python PowerPoint file. it involves the skills related to Python using the com component in windows to operate ppt, which is of great practical value, for more information about how to output all the text in a Python PowerPoint file, see the example below. Share it with you for your reference. The specific analysis is as follows:
The following code depends on windows com, so you must install PowerPoint on the machine to use it. it is very practical to output all plain text information in the pptfile to the specified file.
Import win32comfrom win32com. client import Dispatch, constantsppt = win32com. client. dispatch ('powerpoint. application ') ppt. visible = 1 pptSel = ppt. presentations. open ("c: \ 1.ppt") win32com. client. gencache. ensureDispatch ('powerpoint. application ') f = file ("c: \ 1.txt"," w ") slide_count = pptSel. slides. countfor I in range (1, slide_count + 1): shape_count = pptSel. slides (I ). shapes. count print shape_count for j in range (1, shape_count + 1): if pptSel. slides (I ). shapes (j ). hasTextFrame: s = pptSel. slides (I ). shapes (j ). textFrame. textRange. text f. write (s. encode ('utf-8') + "\ n") f. close () ppt. quit ()
I hope this article will help you with Python programming.