[python-win32] Excel using python

Tim Golden tim.golden at viacom-outdoor.co.uk
Mon Feb 20 09:46:20 CET 2006


[yeswanty devi]

| Hello all,
|          if we have number of excel sheets in a workbook.can 
| we access a selected sheet in the workbook. when i try to 
| acces it always goes to the last sheet. 

I assume this is the kind of thing you want:
(somewhat exaggerated example, but ...)

<code>
import os
import win32com.client

xl = win32com.client.Dispatch ("Excel.Application")
#
# Create a new workbook with a default
#  number of sheets (probably 3)
#
wb = xl.Workbooks.Add ()
print wb.Sheets.Count

sheet0 = wb.Sheets[0]
sheet1 = wb.Sheets[1]
sheet2 = wb.Sheets[2]

sheet0.Name = "First sheet"
sheet1.Name = "Second sheet"
sheet2.Name = "Third sheet"

wb.SaveAs (Filename="c:\\temp\\test.xls")
wb.Close ()
xl.Quit ()

os.startfile ("c:\\temp\\test.xls")

</code>

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


More information about the Python-win32 mailing list