Adding Worksheets to an Excel Workbook

Fabian Braennstroem f.braennstroem at
Fri Oct 13 11:10:43 CEST 2006

Hi Wesley,

* wesley chun <wescpy at> wrote:
>> just a small OT question coming from a linux openoffice
>> system...
>> Does there exist something similar for powerpoint? Would be
>> nice, if anybody can direct me to more examples...
> fabian,
> see below for a PP example.  you mentioned you were coming from a
> linux OOo system... are you trying to do COM stuff with OOo?  i'm not
> familiar with it, but since they do support
> some level of VB-like scripting, i don't believe it's out of the question.
> one thing that i did forget to mention in my earlier message is that i
> use static dispatch for these apps.  if you did not go and run the
> makepy utility, you would have to use dynamic dispatch, start your
> apps with win32com.client.Dispatch(), or, using the same import
> statement as below, win32.Dispatch().

> anyway, here is pretty much the same script as i sent earlier but for
> PowerPoint instead of Excel (the book has small examples for each of
> Excel, Word, PowerPoint, and Outlook):
> # based on ppoint.pyw in Core Python Programming, 2nd ed
> from time import sleep
> import win32com.client as win32
> def ppoint():
>     ppoint = win32.gencache.EnsureDispatch('PowerPoint.Application')
>     pres = ppoint.Presentations.Add()
>     ppoint.Visible = True
>     s1 = pres.Slides.Add(1, win32.constants.ppLayoutText)
>     sleep(1)
>     s1a = s1.Shapes[0].TextFrame.TextRange
>     s1a.Text = 'Python-to-PowerPoint Demo'
>     sleep(1)
>     s1b = s1.Shapes[1].TextFrame.TextRange
>     for i in range(3, 8):
>         s1b.InsertAfter("Line %d\r\n" % i)
>         sleep(1)
>     s1b.InsertAfter("\r\nTh-th-th-that's all folks!")
>     sleep(5)
>     pres.Close()
>     ppoint.Quit()
> if __name__=='__main__':
>     ppoint()

Thanks! I am not able to try it out yet, but as soon as I
get access to my windows machine, I'll give it a try.


More information about the Python-list mailing list