This article describes a method for Python to output all of the text in a PowerPoint (PPT) file. Share to everyone for your reference. The specific analysis is as follows:
The following code relies on Windows COM, so it is very useful to have PowerPoint installed on the machine to output all plain text information in the PPT file to the specified file.
Import win32comfrom win32com.client import Dispatch, constantsppt = Win32com.client.Dispatch (' powerpoint.application ' ) ppt. Visible = 1pptSel = 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 ()
Hopefully this article will help you with Python programming.