Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Save dbf to xls
Message
From
20/02/2013 13:12:06
 
 
To
20/02/2013 07:17:37
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
01566425
Message ID:
01566530
Views:
68
thanks frank and borislav. still getting errors. Here's the whole thing with a recap of the errors i receive at the points i receive them.
when i continue and press ignore each, i end up with a page of dbf files to select from, so it is not finding the CTASK.DBF.
(and Yes it is in the correct directory) (I close all here to make sure there are no lingering selects open.) (When i select CTASK, the test.xlsx is not created.) (To test for interference from previous coding, i jump to this program at startup with the same issues.)

thanks for your patience.
k
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")
>>
>
>Karen,
>
>If you close all the data, then you need to open the table you want before you can refer to it. Change your code to this:
>
>
CLOSE ALL
>USE cTask IN 0
>SELECT cTask
>CopyToExcel("c:\Test Craig's BLOG\Test.XLSX", "Sheet1")
>
>Please note that I do not think it is a good idea to ever CLOSE ALL, but you should close tables individually if you need to.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform