Adding Worksheets to an Excel Workbook

Fabian Braennstroem f.braennstroem at gmx.de
Wed Oct 11 15:55:29 EDT 2006


Hi,

just a small OT question coming from a linux openoffice
system...

* wesley chun <wescpy at gmail.com> wrote:
>> From: e.h.doxtator at accenture.com
>> Date: Tues, Oct 10 2006 2:08 pm
>>
>> I'm a Python newbie, and I'm just getting to the wonders of COM
>> programming.
>
>
> welcome to Python!!  i too, have (recently) been interested in COM
> programming, so much so that i added some material on Microsoft Office
> (Win32 COM Client) Programming to the 2nd ed of my book, "Core Python
> Programming" (see link below).  it's only introductory material, but i
> think you may find it useful as i have, and shows you how to create
> simple applications for Excel, Word, PowerPoint, and Outlook.
>
> in addition to greg's code snippet, here's a snippet based on one from
> the book (the code is under a CC license) -- it doesn't add a new
> sheet, but does let you grab the "active" one (the one that is tabbed
> and facing the user):
>
> # based on excel.pyw in Core Python Programming, 2nd ed
>
> from time import sleep
> import win32com.client as win32
>
> def excel():
>     xl = win32.gencache.EnsureDispatch('Excel.Application')
>     ss = xl.Workbooks.Add() # add a new spreadsheet/workbook
>     sh = ss.ActiveSheet  # grab the active sheet of the workbook
>     xl.Visible = True        # make Excel show up on the desktop
>     sleep(1)
>
>     sh.Cells(1,1).Value = 'Python-to-Excel Demo'
>     sleep(1)
>     for i in range(3, 8):
>         sh.Cells(i,1).Value = 'Line %d' % i
>         sleep(1)
>     sh.Cells(i+2,1).Value = "Th-th-th-that's all folks!"
>
>     sleep(5)
>     ss.Close(False) # close the workbook and don't save
>     xl.Application.Quit() # quit Excel
>
> if __name__=='__main__':
>     excel()
>
> hope this helps!

Does there exist something similar for powerpoint? Would be
nice, if anybody can direct me to more examples...

Greetings!
 Fabian




More information about the Python-list mailing list