I'm testing the displaying of graphs in Excel using code based on an example presented by Cetin Basoz (message #
166097 - code follows). The idea is to open an Excel session to allow the user to finetune the graph after it is displayed. I'm testing it by looping through the example for x number of times. The code works nicely for the first number of graphs but after 30 or so, the system runs out of memory and freezes up. I suppose that I´m not closing the Excel session correctly. Does anyone have any idea how to do this?
Local lnAlen, lnAwidth, llToPrinter
llToPrinter = .F. && Send output directly to printer or open Excel
If Used('CEH') && Get Table to use
Select CEH
Else
Use ? alias CEH
Endif
Select REGION, CEH2, CIIDH2, REMHI2 from CEH INTO ARRAY qPlotter
=AINS(qPlotter,1) && Add Series titles to first row of array
qPlotter(1,1) = "REGION"
qPlotter(1,2) = "CEH"
qPlotter(1,3) = "CIIDH"
qPlotter(1,4) = "REMHI"
lnAlen = ALEN(qPlotter,1) && Array dimentions used to fill Excel cells
lnAwidth = ALEN(qPlotter,2)
Declare INTEGER FindWindow IN Win32API ;
STRING LpClassName, ;
STRING lpWindowName
* 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
If FindWindow("XLMAIN",.NULL.) <> 0 && Application already running
ox = GetObject(,'excel.application')
Else
ox = crea('excel.application') && Create a new application
ox.displayalerts=.f.
ox.workbooks.add()
ox.charts.add()
Endif
with ox.activeworkbook.worksheets(1)
For i = 1 to lnAlen && Fill Excel cells with values from array
For j = 1 to lnAwidth
.Cells(i,j).Value = qPlotter(i,j)
EndFor
Endfor
ox.charts(1).chartwizard(.range(.cells(1,1),.cells(lnAlen,lnAwidth)),xl3dcolumn,4,1,0,1,1,"ChartTitle","REGION","","")
endwith
with ox.charts(1)
.hastitle = .t.
.haslegend = .t.
.ChartTitle.caption = "NUMBER OF xxx PER REGION"
.plotby = 2
* Now play with chart format
#define xlCategory 1
#define xlValue 2 && for Y Axis
#define xlSeriesAxis 1
With .Axes(xlValue) && Y axis
.HasTitle = .T.
with .AxisTitle
.Caption = "NUMBER OF xxx"
.Font.Size = 10
.Font.Bold = .f.
.Orientation = 90 && 90 degrees rotated title
endwith
EndWith
* .charttype = xlLine && Final charttype
If llToPrinter
.PrintOut && Option to print chart directly to printer
oX.quit && Quit excel
Else
oX.visible =.t. && Open Excel
Endif
endwith
oX.quit
Release oX
=sys(3006,val(nlLocaleId))