[python-win32] Excel and Graphing
eric.powell@srs.gov
eric.powell at srs.gov
Thu May 5 15:08:21 CEST 2005
I am close to finishing a project using Excel objects in python to
generate a series of graphs.
However....
I can't get the series to add to the chart properly.
I have an Excel chart with no series on it, so I am trying to add new
series using the Chart.SeriesCollection.NewSeries call, but get the
following error message:
Traceback (most recent call last):
File
"O:\gis\projects\Reactors\Code\Python_Scripts\CMP_PITS_Chart_Tool\chart_tool.py",
line 133, in ?
create_series(filename, graph, series, scell, data, scount)
File
"O:\gis\projects\Reactors\Code\Python_Scripts\CMP_PITS_Chart_Tool\chart_tool.py",
line 70, in create_series
se = chart.SeriesCollection.NewSeries
AttributeError: 'function' object has no attribute 'NewSeries'
Code:
def create_series(filename, graph, series, startcell, data,
scount):#Assumes data is list, graph is a tuple, series is a tuple,
startcell is a tuple
#instatiate the Excel object
xl = win32com.client.Dispatch("Excel.Application")
#Open the workbook
wb = xl.Workbooks.Open (filename)
sh = wb.Sheets('ALLDATA')
#write the data to the proper spot on the spreadsheet
try:
sh.Cells(startcell[0], startcell[1]).Value = series[2] + '_' +
graph[0] + '_' + graph[5]
n = 1
for row in data:
sh.Cells(startcell[0]+n, startcell[1]).Value = row[0]
sh.Cells(startcell[0]+n, startcell[1]+1).Value = row[1]
n = n + 1
chart = wb.Charts(graph[0] + "_" + graph[5])
se = chart.SeriesCollection.NewSeries
se.Name = series[2]
se.XValues = '"=' + graph[0] + '_' + graph[5] + '!R' +
str(startcell[0] +1) + 'C' + str(startcell[1]) + ':R' +
str(startcell[0]+n) + 'C' + str(startcell[1]) + '"'
se.Values = '"=' + graph[0] + '_' + graph[5] + '!R' +
str(startcell[0] +1) + 'C' + str(startcell[1]+1) + ':R' +
str(startcell[0]+n) + 'C' + str(startcell[1]+1) + '"'
xl.ActiveWorkbook.Close(SaveChanges=1)
except:
raise
print "Error Occurred writing data"
xl.ActiveWorkbook.Close(SaveChanges=1)
#Close the workbook
xl.Quit
del xl
Any suggestions as to what exactly I am doing wrong?
Eric B. Powell
E&GIS
BSRI
(803)952-7783
When a true genius appears in this world you may know him by this sign,
that the dunces are all in confederacy against him. (Swift)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20050505/4a760d5c/attachment.html
More information about the Python-win32
mailing list