Tuesday, October 23, 2007

Graphic in Excel automation by VFP

This is just sample exsample, how to make graphic in Excel automation by VFP.. hope can be use for others.. thanks lots

oExcel = CreateObject("Excel.Application")
if vartype(oExcel) != "O"
return .F.
ENDIF

oWorkbook = oExcel.Application.Workbooks.Open("C:\temp\foobar.xls")

oExcel.Range("b2").Value = 56
oExcel.Range("b3").Value = 12
oExcel.Range("b4").Value = 24
oExcel.Range("b5").Value = 33
oExcel.Range("b2").Select()
oExcel.Selection.font.colorindex = 3
oExcel.Selection.font.bold = .t.
oChart = oExcel.Sheets[1].ChartObjects.Add(45.7, 173.2, 319.5, 190.5)
oChart.Activate()
oSourceRange = oExcel.Sheets["Sheet1"].Range("B2:B5")
oExcel.ActiveChart.ChartType = 8
oExcel.ActiveChart.SetSourceData(oSourceRange)
oExcel.ActiveChart.Location(2,oExcel.ActiveSheet.Name)
oExcel.ActiveChart.HasLegend = .T.
oWorkbook.Save()
oExcel.quit()

0 comments: