2010-02-04 184 views
1

這VBA宏的作品:的Python win32com:Excel圖表類型設置爲

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

這段Python(附近),幾乎相當於工作:

from win32com import client 

excel=client.Dispatch("Excel.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 

除了最後一點 - 我不能得到圖表類型爲「xlLine」(普通線圖)。 任何想法?

+0

xlLine工作正常,但對我來說xlColumn和xlBar不。事實上除了xlLine似乎沒有其他的工作。有任何想法嗎? – PrestonDocks 2013-05-14 23:26:10

回答