Pythonとwin32com.clientを使用して、Excel2003の同じプロットに異なるy軸を持つ2つのデータ系列をプロットしようとしています。必要なコードを取得するためにVBAから始めました。これまでのところ、次のようになります。
chart = xlApp.Charts.Add()
# This part successfully creates the first series I want
series = chart.SeriesCollection(1)
series.XValues = xlSheet.Range("L13:L200")
series.Values = xlSheet.Range("M13:M200")
# This is what I added to try to plot the second series
series.AxisGroup = xlPrimary
series2 = chart.SeriesCollection(2)
series2.XValues = xlSheet.Range("L13:L200")
series2.Values = xlSheet.Range("N13:N200")
series2.AxisGroup = xlSecondary
# The rest is for formatting it the way I want, but it doesn't work now that I'm
# to plot the second series. (It stops working when I add the last five lines of code).
chart.Legend.Delete() # Delete legend; MUST BE DONE BEFORE CHART IS MOVED
series.Name = file
chart.Location(2, xlSheet.Name) # Copy chart to active worksheet
chart = xlSheet.Shapes(1)
chart.Top = 51
chart.Left = 240
chart.Width = 500
chart.Height = 350
これは最初のシリーズをプロットしますが、コメントに記載されているように、タイトルの追加、チャートの移動、凡例の削除、またはチャートのサイズ変更は行われません。2番目のシリーズでは何もしません。また、エラーは発生していません。