Re: Adding Worksheets to an Excel Workbook

Discussion in 'Python' started by Fabian Braennstroem, Oct 11, 2006.

  1. Hi,

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

    * wesley chun <> wrote:
    >> From:
    >> 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
    Fabian Braennstroem, Oct 11, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. appu
    Replies:
    1
    Views:
    552
    Mark Rae
    Jan 5, 2007
  2. Replies:
    4
    Views:
    409
  3. wesley chun
    Replies:
    1
    Views:
    410
    Tom Plunket
    Oct 18, 2006
  4. Ratan
    Replies:
    3
    Views:
    97
    Michele Dondi
    Jun 26, 2007
Loading...

Share This Page