*!* The following code determines the selected range of the print area for *!*
*!* the derived Excel file. This is based on the number of fields in the *!*
*!* source table (columns) and the number of records in the source table *!*
*!* (rows). A range of three rows is added to the number of records. This *!*
*!* allows for the following: *!*
*!* One row is added by the COPY TO process to hold the names of the fields. *!*
*!* One row is inserted as a spacer between the field names and the first *!*
*!* row of data. *!*
*!* One row is added to the bottom to contain a SUM function for numeric, *!*
*!* integer, and/or currency data. *!*
lcTotalRangeExpr = ;
["A1:] + ColumnLetter(FCOUNT()) + ALLTRIM(STR(RECCOUNT() + 3)) + ["]
lcTotalPrintArea = ;
["$A$1:$] + ColumnLetter(FCOUNT()) + [$]+ALLTRIM(STR(RECCOUNT() + 3)) + ["]
*!* The following code will erase any previously created temporary excel *!*
*!* file created by this program *!*
IF FILE(HOME() + "VFP_to_Excel.xls")
ERASE HOME() + "VFP_to_Excel.xls"
endif
*!* The following code creates the temporary Excel file that will be used *!*
*!* for the derived Excel file *!*
COPY TO HOME() + "VFP_to_Excel" TYPE XL5
*!* The following code commences the OLE Automation process. *!*
oExcelObject = CREATEOBJECT('Excel.Application')
*!* The following code opens the "VFP_to_Excel" file that was created by the *!*
*!* "COPY TO" command *!*
oExcelWorkbook = ;
oExcelObject.Application.Workbooks.Open(HOME() + "VFP_to_Excel")
*!* The following code activates the Worksheet which contains the "COPY TO" *!*
*!* data *!*
oActiveExcelSheet = oExcelWorkbook.Worksheets("VFP_to_Excel").Activate
*!*oExcelWorkbook.Worksheets.add
*!*oExcelWorkbook.Worksheets.Item(1).name="rahq1"
&&oExcelWorkbook.Worksheets("VFP_to_Excel").move
oActiveExcelSheet = oExcelWorkbook.Worksheets("VFP_to_Excel").Activate
*!* The following code establishes an Object Reference to the "VFP_to_Excel" *!*
*!* worksheet *!*
oExcelSheet = oExcelWorkbook.Worksheets("VFP_to_Excel")
oExcelSheet.name="示例"
*!* The following code sets the paper size and orientation variables based *!*
*!* on the lnPaperOrientation value *!*
DO CASE
CASE lnPaperOrientation = 2
lnPaperSize = 1
lnPrintOrientation = 2
CASE lnPaperOrientation = 3
lnPaperSize = 5
lnPrintOrientation = 1
CASE lnPaperOrientation = 4
lnPaperSize = 5
lnPrintOrientation = 2
OTHERWISE
lnPaperSize = 1
lnPrintOrientation = 1
ENDCASE
*!* The following code determines whether or not there is a table open in *!*
*!* the currently selected work area. *!*
lcTableAlias = ALIAS()
IF EMPTY(lcTableAlias)
=MESSAGEBOX("A table must be open in the currently selected work area" + ;
CHR(13) + "in order for this program to work.")
aa=GETFILE("dbf")
IF !EMPTY(aa) AND FILE(aa)
SELECT 0
USE (aa)
else
RETURN && If no table is open, then return *!*
endif
ENDIF
*!* The following code determines the derived Excel file name and location. *!*
lcTablePath = LEFT(DBF(), RAT("\", DBF()))
lcExcelFile = lcTablePath + lcTableAlias + ".xls"
IF FILE(lcExcelFile) && If a file by the derived name already *!*
*!* exists in the derived location *!*
lcMessageText = "An Excel file by the name of " + lcTableAlias + ;
".xls" + CHR(13) + "already exists at location:" + CHR(13) + ;
lcTablePath + CHR(13) + ;
"Do you want to delete it now and replace it?"
lnDialogType = 4 + 32 + 256
lnFirstWarning = MESSAGEBOX(lcMessageText, lnDialogType)
IF lnFirstWarning = 6 && User responds with a "Yes" *!*
lcMessageText = "This will delete the exist file:" + CHR(13) + ;
lcExcelFile + CHR(13) + ;
"Are you certain?"
lnDialogType = 4 + 48 + 256
lnSecondWarning = MESSAGEBOX(lcMessageText, lnDialogType)
IF lnSecondWarning = 6 && User responds with a "Yes" *!*
ERASE (lcExcelFile) && Erase the existing file *!*
ELSE
RETURN
ENDIF
ELSE
RETURN
ENDIF
ENDIF