开发者

Python win32com: Excel set chart type to Line

This VBA macro works:

Sub Draw_Graph()
    Columns("A:B").Select
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.SetSourceData Source:=ActiveSheet.Range("$A:$B")
    ActiveChart.ChartType = xlLine
End Sub

This Python (near) Equivalent almost works:

from win32com import client

excel=client.Dispatch("开发者_如何学JAVAExcel.Application")
excel.Visible=True
book=excel.Workbooks.Open("myfile.csv", False, True)
sheet=book.Worksheets(1)
chart=book.Charts.Add()
chart.SetSourceData(sheet.Range("$A:$B"))
chart.ChartType=client.constants.xlLine

Apart from the last bit - I can't get the chart type to be "xlLine" (plain line graph). Any ideas ?


Needed to run the 'makepy.py' to get it to work.

http://docs.activestate.com/activepython/2.4/pywin32/html/com/win32com/HTML/QuickStartClientCom.html#UsingComConstants

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜