[Tutor] win32 and excel

Bob Gailer ramrom@earthling.net
Tue Feb 25 09:44:30 2003


--=======24237E6F=======
Content-Type: text/plain; x-avg-checked=avg-ok-56086167; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit

In my experience with Excel chart data needs to be arranged thus:

Date:           2/3/2003        2/4/2003        2/5/2003 etc
Apples Sold     3               5               9         etc

Assuming this data is in A1:I2:

import win32com.client
ex = win32com.client.Dispatch("excel.application")
ex.visible = 1
wb = ex.workbooks.open('c:\\xxx\\book1.xls')
wk = ex.Worksheets(1) # worksheet
chartobject1 = wk.chartobjects(1)
chart1 = chartobject1.chart # chart
range = ex.Range("A1:I2")
chart1.seriescollection.add(range)

If the initial worksheet has the data in the format you showed:

Date:           Apples Sold:
2/3/2003        3
2/4/2003        5
2/5/2003        9

Then (I think) you'll need to transpose it. If you are filling those cells 
from the Python program, just fill them in the order I gave above.

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625

--=======24237E6F=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-56086167
Content-Disposition: inline


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.454 / Virus Database: 253 - Release Date: 2/10/2003

--=======24237E6F=======--