I need to change the formula of a chart in excel using python, to find out how to do it I recorded a macro and this is what I got :
ActiveSheet.ChartObjects("Graphique 1").Activate
ActiveChart.Axes(xlCategory).Select
ActiveSheet.ChartObjects("Graphique 1").Activate
ActiveChart.SeriesCollection(1).Values = "='Données'!$ET$68:$IJ$68"
ActiveChart.SeriesCollection(1).XValues = "='Données'!$ET$1:$IJ$1"
So my chart is apparently called Graphique 1 and according to the excel documentation ChartObjects is called on the worksheet objet. easy right?
However nothing seems to work :
from win32com import client
xl = client.Dispatch("Excel.Application")
xl.Visible = 1
workbook = xl.Workbooks.Open(r"D:\some\path\file.xls")
ws = workbook.Sheets("the sheet")
#tried but did not work :
ws.ChartObjects("Graphique 1").Activate = True #Exception occured : no element with this name
ws.ChartObjects("Graphique 1").Activate = 1 #Exception occured : no element with this name
ws.ChartObjects(1).Activate = True #Exception occured : no message
ws.ChartObjects(1).Activate = 1 #Exception occured : no message
#in case it's 0ed indexed
ws.ChartObjects(0).Activate = True #Exception occured : no message
ws.ChartObjects(0).Activate = 1 #Exception occured : no message
print ws.ChartObjects("Graphique 1").SeriesCollection(1).Values #Exception occured : no element with this name
print ws.ChartObjects(1).SeriesCollection(1).Values #Exception occured : no message
Any ideas? Thanks.
Ps : I don't really now a lot of things about excel, I have 10 sheets, I supose that my chartObject is on the sheet were it's being draw
EDIT
weirdly a ChartObjects count of each sheet return 0, how can it be? I can see it with my own eyes
>>> for i in range(1,10):
ws = workbook.Sheets(i)
co = ws.ChartObjects()
count = co.Count
print count
0
0
0
0
0
0
0
0
0