* Simple automation with Excel. Just copy this faq into prg file and run it.
* include an EXCEL header file and reference values by name.
* #INCLUDE C:\MyProject\INCLUDE\xl5en32.h
* If you do not have a header file and need to create one. Refer to FAQ:
* How to create office header files in VFP FAQ184-2749
* creates random numbers for quarterly data.
* adds some detail records
CREATE CURSOR curCompany (Company C(20), Qtr1 N(10,2), qtr2 N(10,2), qtr3 N(10,2), qtr4 N(10,2))
FOR lni = 1 TO 10
APPEND BLANK
REPLACE curCompany.company WITH SYS(2015)
REPLACE curCompany.qtr1 WITH 1 + 1000 * RAND( )
REPLACE curCompany.qtr2 WITH 1 + 1000 * RAND( )
REPLACE curCompany.qtr3 WITH 1 + 1000 * RAND( )
REPLACE curCompany.qtr4 WITH 1 + 1000 * RAND( )
ENDFOR
* Excel: HorizontalAlignment
* 2 = Left
* 3 = Center
* 4 = Right
local oExcel, oSheet
oExcel = CreateObject([Excel.Application])
oExcel.Visible = .T.
oExcel.Workbooks.Add()
oSheet = oExcel.ActiveSheet
lnRow = 0
SELECT curCompany
GO TOP
DO WHILE NOT EOF()
lnRow = lnRow + 1
IF lnRow = 1
oSheet.Cells(lnRow,1).Value = [FoxPro Rocks!]
* Create the formula rather than hardcoding total so the user can
* change the spreadsheet and it will reflect new totals.
* Example: =SUM(D510)
FOR lni = 1 TO 4
lcFormula = [=SUM(] + CHR(64 + lni) + ALLTRIM(STR(m.lnBeginRange)) + [:] +;
CHR(64 + 3 + lni) + ALLTRIM(STR(m.lnRow)) + [)]
***************************************************** Late Edition.
These miscellaneous Excel automation command are compliments of jrbbldr
JRB-Bldr
VisionQuest Consulting
Business Analyst & CIO Consulting Services
CIOServices@yahoo.com
*****************************************************
* --- Save Excel Results ---
oExcel.CutCopyMode = .F. && Clear the clipboard from previous Excel Paste
oExcel.DisplayAlerts = .F.
* --- Save Results ---
xlSheet.SAVEAS(mcExclFName)
* --- Close the Worksheet ---
oExcel.workbooks.CLOSE
* --- Quit Excel ---
oExcel.QUIT
RELEASE oExcel
tmpsheet = CREATEOBJECT('excel.application')
oExcel = tmpsheet.APPLICATION
oExcel.ReferenceStyle = 1 && Ensure Columns in A-B Format instead of 1-2 Format
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.