0

我正在尝试使用 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

这绘制了第一个系列,但如评论中所述,不再添加标题、移动图表、删除图例或调整图表大小。它与第二个系列无关。它也不会产生错误。

4

0 回答 0