Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
FoxPro and Excel
Message
 
 
To
17/09/1999 13:54:31
General information
Forum:
Visual FoxPro
Category:
Reports & Report designer
Miscellaneous
Thread ID:
00266061
Message ID:
00266110
Views:
43
>Is it possible somehow to export a foxrpro report to excel? I don't really care about the formatting but the subtotalling and grouping is important to me...
>
>I am evaluating the possibility to use Crystal Reports but it seems that there may be a method since this flexibility appears to be standard in Access..
>
>Linos

Not directly with the REPORT command. I create an Excel object then populate the cells, etc. The following code is what I use to create a spreadsheet of an employee's timecard. I think I got all the other methods included at the end as well. At the end, I do a SaveAs to both a Lotus and Excel file.
#INCLUDE XL97Cons.h
*
* Create the Excel file and SaveAs a Lotus 1-2-3 file
*
select TimeCard_V2
locate
local lnRow, ox, lcFileName, ldLeaveDate, lnEmpID, lnRetval, lcLocalDrive
lcLocalDrive = sys(5) + sys(2003)
lcFileName = alltrim(substr(LastName, 1, 8))

ox = newobject('excel.application')
ox.workbooks.add

lnRow = 1

ox.sheets(1).cells(lnRow, 1) = FirstName
This.mSetFont(ox.sheets(1).cells(lnRow, 1))
ox.sheets(1).cells(lnRow, 2) = LastName
This.mSetFont(ox.sheets(1).cells(lnRow, 2))

lnRow = 3

ox.sheets(1).cells(lnRow, 1) = "Date"
This.mSetFont(ox.sheets(1).cells(lnRow, 1))
ox.sheets(1).cells(lnRow, 2) = "Time In"
This.mSetFont(ox.sheets(1).cells(lnRow, 2))
ox.sheets(1).cells(lnRow, 3) = "Time Out"
This.mSetFont(ox.sheets(1).cells(lnRow, 3))
ox.sheets(1).cells(lnRow, 4) = "Lunch"
This.mSetFont(ox.sheets(1).cells(lnRow, 4))
ox.sheets(1).cells(lnRow, 5) = "Net Hours"
This.mSetFont(ox.sheets(1).cells(lnRow, 5))
ox.sheets(1).cells(lnRow, 6) = "Accrued"
This.mSetFont(ox.sheets(1).cells(lnRow, 6))
ox.sheets(1).cells(lnRow, 7) = "Used"
This.mSetFont(ox.sheets(1).cells(lnRow, 7))
ox.sheets(1).cells(lnRow, 8) = "Other Leave"
This.mSetFont(ox.sheets(1).cells(lnRow, 8))

lnRow = 4

scan
	ox.sheets(1).cells(lnRow, 1) = Date_In
	ox.sheets(1).cells(lnRow, 2) = This.mGetTime(Time_In, AmPm_In)
	ox.sheets(1).cells(lnRow, 3) = This.mGetTime(Time_Out, AmPm_Out)
	ox.sheets(1).cells(lnRow, 4) = Lunch_Dur
	This.mFormatDecimals(ox.sheets(1).cells(lnRow, 4), 2)
	ox.sheets(1).cells(lnRow, 5) = Net_Hours
	This.mFormatDecimals(ox.sheets(1).cells(lnRow, 5), 2)
	ox.sheets(1).cells(lnRow, 6) = Accrued
	This.mFormatDecimals(ox.sheets(1).cells(lnRow, 6), 2)
	lnEmpID = Employee.KeyID
	ldLeaveDate = Date_In
	select Leave_V2
	requery("Leave_V2")
	locate
	do while !eof()
		lnRow = lnRow + 1
		ox.sheets(1).cells(lnRow, 1) = ldLeaveDate
		ox.sheets(1).cells(lnRow, 7) = CompUsed
		This.mFormatDecimals(ox.sheets(1).cells(lnRow, 7), 2)
		ox.sheets(1).cells(lnRow, 8) = OtherUsed
		This.mFormatDecimals(ox.sheets(1).cells(lnRow, 8), 2)
		skip
	enddo
	select TimeCard_V2
	lnRow = lnRow + 1
endscan

lnRow = lnRow + 2
ox.sheets(1).cells(lnRow, 1) = "Credit Balance"
ox.sheets(1).cells(lnRow, 2) = str(Employee.Balance, 5, 2)
ox.sheets(1).cells(lnRow, 3) = "As Of"
ox.sheets(1).cells(lnRow, 4) = Employee.BalDate
This.mFormatDecimals(ox.sheets(1).cells(lnRow, 2), 2)

if file(addbs(lcLocalDrive) + lcFileName + ".xls")
	erase addbs(lcLocalDrive) + lcFileName + ".xls"
endif
if file(addbs(lcLocalDrive) + lcFileName + ".wk4")
	erase addbs(lcLocalDrive) + lcFileName + ".wk4"
endif

ox.activeworkbook.saveas(addbs(lcLocalDrive) + lcFileName + ".wk4", xlWK4, .F.)
ox.activeworkbook.saveas(addbs(lcLocalDrive) + lcFileName + ".xls", xlNormal)
ox.quit
ox = .null.
release ox
return addbs(lcLocalDrive) + lcFileName


procedure mSetFont
*
lparameter loCell
With loCell.Font
	.Name = "Arial"
	.FontStyle = "Bold"
	.Size = 10
endwith
return


Procedure mTimeFormat
*
lparameter loCell
loCell.NumberFormat = "h:mm"
return


Procedure mFormatDecimals
*
lparameter loCell, lnDecimals
if pcount() < 1 or type("lnDecimals") <> "N"
	lnDecimals = 2
endif
local lcMask
lcMask = "0." + replicate("0", lnDecimals)
loCell.NumberFormat = lcMask
return
Mark McCasland
Midlothian, TX USA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform