开发者

Python win32com: Excel set chart type to Line

开发者 https://www.devze.com 2022-12-19 00:06 出处:网络
This VBA macro works: Sub Draw_Graph() Columns(\"A:B\").Select ActiveSheet.Shapes.AddChart.Select ActiveChart.SetSourceData Source:=ActiveSheet.Range(\"$A:$B\")

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

精彩评论

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