Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OLE Automation Creation of an Excel Chart within an Shee
Message
From
15/12/1999 11:09:39
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00304011
Message ID:
00304109
Views:
33
>Using Visual FoxPro 5.0 and Excel 97 what is the best way to create an excel chart within a sheet and have complete control through code in FoxPro to manipulate the chart. the chart is not embedded in a form it would be within a worksheet created with CREATEOBJECT("Excel.Application")
>I've been trying without success.


Martin,
Not the "best" way but a starter :
* Part of xlChartType constants
#Define xl3DArea 					-4098
#Define xl3DColumn					-4100
#Define xl3DLine					-4101
#Define xl3DPie						-4102
#Define xlArea						1
#Define xlBubble3DEffect			87
#Define xlLine						4
#Define xlPie						5
#Define xlRadar						-4151
#Define xlSurface					83

*** set the LOCALEID to English
nlLocaleId=sys(3004)		&& Save local id
=sys(3006,1033)			&& We will be sending instructions in English
ox = crea('excel.application')
ox.workbooks.add()
With ox.activeworkbook.worksheets(1)
  .Cells(1,1).Value = "NumProd1"
  .Cells(1,2).Value = "AMount"
  .Cells(1,3).value = "Quota"
  .Cells(2,1).Value = 113
  .Cells(2,2).Value = 12000
  .Cells(2,3).value = 23
  .Cells(3,1).Value = 254
  .Cells(3,2).Value = 45000
  .Cells(3,3).value = 24
  .Cells(4,1).Value = 165
  .Cells(4,2).Value = 37000
  .Cells(4,3).value = 42
  ox.charts.add()
  ox.charts(1).chartwizard(.range(.Cells(1,1),.Cells(4,3)),xl3DColumn,4,1,0,1,1,"","","","")
Endwith
With ox.charts(1)
  .hastitle = .t.
  .haslegend = .t.
  .ChartTitle.caption = "This is chart title"
*	.ChartType=xlBubble3DEffect  && Set a charttype
  .plotby = 2
* Now play with chart format
  #Define xlCategory		1
  #Define xlValue			2
  #Define xlSeriesAxis	3
  With .Axes(xlValue)
    .hastitle = .T.
    With .AxisTitle
      .Caption = "This is Rotated Value title"
      .Font.Size = 10
      .Font.Bold = .f.
      .Orientation = 90 && Show 90 degrees rotated - clockwise
    Endwith
  Endwith
  .charttype = xl3DLine  && Change charttype in between
*    	.PrintOut   && Print chart
  ox.visible = .t.
Endwith
*oX.activeworkbook.saved = .t. && Suppress save dialog
*oX.quit      && Quit excel
=sys(3006,val(nlLocaleId))
Not best way because cells().value is the slowest method to populate excel cells and there are much more options then in sample that could be set (I prefer wrapper routines for them). To speed up data sending to excel if your datasheet is large, either save data as an xls file (csv, delimited are other options) or create a tab delimited string, copy to clipboard and paste in excel. There are some quirks in excel syntax if you don't check what a PEM applies to. ie: You might incorrectly call :
ox.worksheets(1).cells(1,4) to change the data on the fly and bomb. Because worksheets is hierarchically an object of a workbook :
ox.workbooks(1).worksheets(1).cells(1,4).value
it should be. Of course 1 is just a sampling. It would be either correct index or name (or activeworkbook, activesheet, activecell etc)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform