Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Creating excel graphics from vfp
Message
De
17/01/2002 16:18:46
 
 
À
17/01/2002 13:21:34
Steve Summers
Pima County Superior Court
Tucson, Arizona, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00606233
Message ID:
00606394
Vues:
83
>Hi there,
>Have any of you ever created an excel graphic from vfp? If so, please share.
>This is what I am doing:
>1) pull data from legacy system SDF file
>2) create a vfp table from the SDF file
>3) Run some SELECT statments to come up with some statistical counts
>4) From the results of the SELECT statment I need to create PIE charts
>5) The VFP report should include the SELECT statements results along with the PIE chart, that I am trying to create in Excel.
>
>By automating excel I've been able to export the SELECT statment results into an excel spreadsheet, and highlight the data range I need to create the PIE chart from, then WHAT? That is my question. Or is there any other way to do it?
>
>Any advice is greatly appreciated.
>Have a wonderful Thursday.


The following code is a simple example on how to create a chart from one of the applications I developed recently.

STEP 1

!Select allt(str(stud_no)) as studno , sum(c_amount) as checking, ;
sum(s_amount)as Savings,sum(c_amount) + sum(s_amount) as total from bankacct;
where trans = "D" and stud_no <> 10 and stud_no <> 15 ;
order by total descending ;
group by 1 into table grades
fileopen = .f.
On error store .t. to fileopen


STEP 2
** creating the xls spreadsheet
Select grades
Copy fields studno , checking, Savings to c:\gnj\foxtoexcel\grades.xls type xls


STEP 3
*** creating the chart in Excel
ExcelOpened = .F.
fname = "c:\gnj\foxtoexcel\grades.xls"
sheetnum = 1
ab_sheet = 4
chtype = 52
viewer = 1
mybook = ""
mviewer = 1
chrttitle = "Checking and Saving Balances by Student"
chrtxaxis = "Student No." &&& X-Axis
chrtyaxis = "Bank and Savings" &&& Y-axis
rangbeg = "A1"
rangend = "C25"
ChRANGE = alltrim(rangbeg)+":"+alltrim(rangend)
oExcel = CREATEOBJECT("Excel.Application")
If ISNULL(oExcel)
Messagebox('Excel Object was Not created' 16 , "Warning")
Return
Endif

*** chart is not a pie chart - look in Excel documentation for the number for a pie chart

Activesheet = ALLTRIM(fname)
oExcel.Workbooks.OPEN(Activesheet)
With oExcel
.range("B1").select
.activecell.formular1c1 = "Bank"
.range("C1").select
.activecell.formular1c1 = "Savings"
.RANGE(ChRANGE).SELECT
.charts.ADD()
.charts("chart1").hastitle=.T.
.charts("chart1").chartTitle.TEXT= chrttitle
.charts("chart1").chartTitle.font.size = 18 && can make into variable
.charts("chart1").plotarea.WIDTH=600 && can make into variable
.charts("chart1").plotarea.HEIGHT=300 && can make into variable
.charts("chart1").axes(1).hastitle=.t.
.charts("chart1").axes(1).AxisTitle.text= chrtxaxis
.charts("chart1").axes(1).AxisTitle.font.Size = 14
.charts("chart1").axes(2).hastitle=.t.
.charts("chart1").axes(2).AxisTitle.text= chrtyaxis
.charts("chart1").axes(2).AxisTitle.Font.Size= 14
.charts("chart1").haslegend = .T. && displays legend if .t.
.charts("chart1").TYPE= chtype
.VISIBLE = .T.
.charts("chart1").printout() && print chart
Endwith

oExcel.QUIT()

There are probably other ways of doing this. However, to fully understand what is happening, try running a macro creating the spreadsheet first in Excel and then looking at the code that the Excel macro created and converting it to VFP code. Hopefully the above should help.

Gaylen
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform