close all use CTASK in 0 SELECT CTASK CopyToExcel("c:\DB\Test.XLSX", "Sheet1") ********************************** FUNCTION AppendFromExcel(tcXLSFile, tcSheet, tvWorkarea, tcExcelFieldList, tcExcelWhereExpr, tcTableFieldList, tcTableForExpr, tlNoHeaderRow) ********************************** FUNCTION CopyToExcel(tcXLSFile, tcSheet, tvWorkArea, tcExcelFieldList, tcTableFieldList, tcTableForExpr) *********************************** * PARAMETER Information * tcXLSFile := a string specifying an excel file (*.xls, *.xlsx, *.xlsm, *.xlsb) on disk * tcSheet := a string specifying the name of the worksheet to create within the excel workbook * tvWorkarea [optional] := the Alias, Work Area, or File Name of the table you want to be copied to the worksheet (default is currently selected Alias) * tcExcelFieldList [optional] := a comma delimited list of columns you want to create in the worksheet (default is '*' - columns will match table field list) * tcTableFieldList [optional] := a comma delimited list of fields you want this function to copy from tvWorkArea * tcTableForExpr [optional] := a valid VFP Where/For clause to be used when querying tvWorkArea for data to be copied to the worksheet * * RETURN Information * returns numeric, the number of records inserted into the worksheet * * Provider Information * the default provider being used in the SQLStringConnect function can be downloaded and installed from: * http://www.microsoft.com/downloads/details.aspx?FamilyID=7554F536-8C28-4598-9B72-EF94E038C891&displaylang=en ********************************** #DEFINE adOpenStatic 3 #DEFINE adOpenKeyset 1 #DEFINE adLockOptimistic 3 #DEFINE adUseClient 3 #DEFINE adUseServer 2 #DEFINE adCmdText 0x0001 LOCAL loConnection as ADODB.Connection, lcCreateTableCommand, llOpenedtvWorkArea, loExc as Exception, ; lnReturn, lnResult, lnFieldCounter, lnSQL, loCursorAdapter as CursorAdapter, ; lcFieldName, lcFieldType, lcSelectFields, lcUpdateNameListFields, lcUpdatableFieldList, ; loRecordSet as ADODB.Recordset, lcConversionFunc, lcVFPFieldName, laTableFields[1], laErr[1] m.lnSelect = SELECT(0) m.lnReturn = 0 m.llOpenedtvWorkArea = .F. IF !USED(m.tvWorkarea) AND TYPE("m.tvWorkArea") = "C" AND FILE(DEFAULTEXT(m.tvWorkarea,"DBF")) &&& ERROR 1 **** ***** TABLE NUMBER IS INVALID ****** SELECT 0 USE (DEFAULTEXT(m.tvWorkarea,"DBF")) SHARED AGAIN &&&& ERROR 2 ****** ***** FUNCTION ARUGUMENT,TYPE, OR COUNT IS INVALID m.tvWorkarea = ALIAS() m.llOpenedtvWorkArea = .T. ELSE IF !USED(m.tvWorkarea) m.tvWorkarea = ALIAS() ENDIF ENDIF IF TYPE("m.tvWorkArea") = "N" m.tvWorkArea = ALIAS(m.tvWorkArea) ENDIF>>this is it and beginning of Craig's program
>>close all >>SELECT ctask >>CopyToExcel("c:\Test Craig's BLOG\Test.XLSX", "Sheet1")>>
CLOSE ALL >USE cTask IN 0 >SELECT cTask >CopyToExcel("c:\Test Craig's BLOG\Test.XLSX", "Sheet1")>