Creating Charts in Excel with pyExcelerator.ExcelMagic

implicate_order dwai.lahiri at gmail.com
Tue Aug 15 14:17:08 EDT 2006


Greetings,

I'm new to python and am in the process of writing a script to parse
some CSV data, spread it across multiple Excel worksheets and then
generate charts. I searched the internet to find some place where I
could look up a HOWTO doc/recipe to do that using either pyExcelerator
or win32com.client.

Could someone point me in the right direction?
I'm at the stage where the spreadsheet and associated data worksheets
are ready. The chart is created (with win32com.client).  I need to know
how I can use win32com.client to actually generate some data based on
the contents of a particular work sheet.

>>> from win32com.client import *
>>> xl = win32com.client.Dispatch("Excel.Application")
>>> wb = xl.Workbooks.open("C:\scripts\dummytest.xls")
>>> xl.Visible = 1
>>> ws = wb.Worksheets(1)
>>> ws.Range('$A1:$D1').Value = ['NAME', 'PLACE', 'RANK', 'PRICE']
>>> ws.Range('$A2:$D2').Value = ['Foo', 'Fooland', 1, 100]
>>> ws.Range('$A3:$D3').Value = ['Bar', 'Barland', 2, 75]
>>> ws.Range('$A4:$D4').Value = ['Stuff', 'Stuffland', 3, 50]
>>> wb.Save()
>>> wb.Charts.Add()
>>> wc1 = wb.Charts(1)

At this point, I'm lost -- I couldn't find any lucid docs to indicate
what can be done to populate the chart from the worksheet "ws".

Any help would be greatly appreciated.

TIA




More information about the Python-list mailing list