我正在尝试使用Python和win32com.client在Excel 2003中的同一图中绘制两个具有不同y轴的数据系列。我从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
这绘制了第一个系列,但正如评论中所述,不再添加标题,移动图表,删除图例或调整图表大小。它对第二个系列没有任何作用。它也没有产生错误。