Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 data file export to Xls. format in Different Sheet -VFP6 1

Status
Not open for further replies.

omr1119

Programmer
Oct 7, 2003
34
0
0
PH
Hi,

Is there any command to save 2 data file and export in One Filename in excel format and will save in different Sheet?
i.e:sheet1, sheet2

Thanks In Advance:)

Omr:)


 
You may need to use some type of automation.

Copy the code below in a prg and run it.

* include an EXCEL header file and reference values by name.
*#INCLUDE C:\MDOTVFPCLASS\INCLUDE\xl97cons.h
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!"

lnRow = 3
lnCol = 3
oSheet.Range("C3").Select
oSheet.Cells(lnRow,lnCol).Value = "Qtr 1"
oSheet.Cells(lnRow,lnCol).Font.Bold = .T.

*oSheet.Cells(lnRow,lnCol).HorizontalAlignment = xlCenter
oSheet.Cells(lnRow,lnCol).HorizontalAlignment = 3

lnCol = lnCol + 1
oSheet.Range("D3").Select
oSheet.Cells(lnRow,lnCol).Value = "Qtr 2"
oSheet.Cells(lnRow,lnCol).Font.Bold = .T.
*oSheet.Cells(lnRow,lnCol).HorizontalAlignment = xlCenter
oSheet.Cells(lnRow,lnCol).HorizontalAlignment = 3

lnCol = lnCol + 1
oSheet.Range("E3").Select
oSheet.Cells(lnRow,lnCol).Value = "Qtr 3"
oSheet.Cells(lnRow,lnCol).Font.Bold = .T.
*oSheet.Cells(lnRow,lnCol).HorizontalAlignment = xlCenter
oSheet.Cells(lnRow,lnCol).HorizontalAlignment = 3

lnCol = lnCol + 1
oSheet.Range("F3").Select
oSheet.Cells(lnRow,lnCol).Value = "Qtr 4"
oSheet.Cells(lnRow,lnCol).Font.Bold = .T.
*oSheet.Cells(lnRow,lnCol).HorizontalAlignment = xlCenter
oSheet.Cells(lnRow,lnCol).HorizontalAlignment = 3

lnRow = 4
lnBeginRange = lnRow
ENDIF

oSheet.Cells(lnRow,1).Value = curCompany.Company
oSheet.Cells(lnRow,3).Value = curCompany.qtr1
oSheet.Cells(lnRow,4).Value = curCompany.qtr2
oSheet.Cells(lnRow,5).Value = curCompany.qtr3
oSheet.Cells(lnRow,6).Value = curCompany.qtr4

SKIP
ENDDO

* Example: =SUM(D5:D10)
FOR lni = 1 TO 4
lcFormula = "=SUM(" + CHR(64 + lni) + ALLTRIM(STR(m.lnBeginRange)) + ":" +;
CHR(64 + 3 + lni) + ALLTRIM(STR(m.lnRow)) + ")"


oSheet.Cells(lnRow+1,2+lni).Formula = "&lcFormula"
ENDFOR

IF .T.
oExcel.Sheets("Sheet2").Select
oSheet = oExcel.ActiveSheet

oSheet.Cells(2,2).Value = "Now I am entering data on a new sheet."
oSheet.Cells(4,2).Value = "Pretty Cool"
oSheet.Cells(6,2).Value = "Fox Rocks!"
ENDIF


Jim Osieczonek
Delta Business Group, LLC
 
Jim,

Thanks:) this solve my problem.

a star for u:)

Omr:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top