[Tutor] win32com and python

Pierre Barthelemy barthpi at gmail.com
Tue Apr 19 16:53:13 CEST 2011


Hello,

I would need to control a powerpoint file from python. I have
installed the win32com library for python, then i used makepy to
create a powerpoint-specific library.

The things i need to do are pretty basic: open a file, create a new
slide, place a picture and a comment to the picture.

The problem i have is that, often, while the script is running, the
powerpoint file would already be open. In this case, my script would
open it anew, and make the modifications in the newly opened file.
To prevent that problem, i need to be able to look at the filenames of
the open powerpoint files.
It there a way to do that ?

And, by the way, is there any kind of help or manual or document to
understand how to use win32com and the related application-specific
libraries ?

The code i am using now is the following:
[code]
import win32com.client
import win32com.gen_py.ppt11b as ppt11b


ppt = win32com.client.Dispatch("Powerpoint.Application") #Open the
powerpoint application
ppt.Visible = True
pptfile = ppt.Presentations.Open('FileName',ReadOnly=0, Untitled=0,
WithWindow=1)#Open the desired ppt file

Slide = pptfile.Slides.Add(len(pptfile.Slides)+1, ppLayoutBlank)
shape1 = Slide.Shapes.AddTextbox(Orientation=0x1,Left=100,Top=50,Width=400,Height=100)
shape1.TextFrame.TextRange.Text='Trial'

shape2=Slide.Shapes.AddPicture(FileName='PictureName',
LinkToFile=False, SaveWithDocument=True, Left=100, Top=100, Width=400,
Height=400)
pptfile.Save()
pptfile.Close()
[\code]


More information about the Tutor mailing list