Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
COPY TO an Excel - including Memo fields
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00844067
Message ID:
01127515
Vues:
40
Here is one of the methods. It however creates the tgable with memo fields only, so you will need to alter the table.
DO iExportMemo     && from FoxPro2Excel
DO iImportMemo      && from Excel2Foxpro

Return
*------------------------
Procedure iImportMemo
*Import from Excel
store SQLSTRINGCONNECT(;
	"DRIVER={Microsoft Excel Driver (*.xls)};" + ;
	"FIL=Excel 97;" + ;
	"DefaultDir=c:\;" + ;
	"DBQ=c:\book1.xls");
	TO gnConnHandle	

*gnConnHandle=SQLCONNECT("Excel Files") && to get the files dialog 
CURSORSETPROP("FetchMemo",.t.,0)   && set cursor properties in advance

?SQLexec(gnConnHandle, 'select * from "sheet1$"')
sqldisc(0)

* Compare results
USE c:\yy IN 0 ORDER keyfld
SET RELATION TO ALLTRIM(fieldc) INTO yy
LOCATE FOR NOT fieldm==yy.fieldm
?found()

Return
*-------------------------------
Procedure iExportMemo
CLOSE TABLES all
clear
* create TABLE
CREATE TABLE c:\yy (fieldc c(10), fieldm Memo)
FOR ia=1 TO 10
	insert into yy VALUES (PADL(ia,10,"0"), ;
				REPLICATE("Expression"+PADL(ia,10,"0"),ia*100))
ENDFOR
INDEX ON fieldc TAG keyfld
USE

* Export to Excel
oExcel= CREATEOBJECT("Excel.Application")
oExcel.DisplayAlerts = .f.
oExcel.Workbooks.Add()
oExcel.visible=.t.

ConnectionString="ODBC;DSN=Visual FoxPro Tables;UID=;PWD=;SourceDB=c:\;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;"
sqlquery="SELECT * FROM c:\yy.dbf"

oExcel.ActiveSheet.QueryTables.Add(;
		ConnectionString,;
		oExcel.ActiveSheet.Range("A1"),;
		sqlquery).Refresh

oExcel.activeworkbook.saveas("c:\book1.xls")

oExcel.quit
oExcel=.null.
Return
*-----------------------------
>How would you import long field into DBF?
>
>E.g.
 lcRange = "A1:"
>			lcRange = m.lcRange + chr(64 + m.lnCols) + alltrim(str(m.lnRows))
>			loSheet.range(m.lcRange).select
>
>			lcStr = strtran(m.lcStr,space(1),"_")
>			lcStr = strtran(m.lcStr,".","_")
>			lcStr = upper(strtran(upper(justfname(m.tcInputFile)),".XLS","") + ;
>				"(" + m.lcStr + ")")
>
>			OleApp.DisplayAlerts = .f.
>
>*#DEFINE xlDBF3	8
>
>			OleApp.ActiveWorkbook.saveas(sys(5)-curdir()- m.lcStr, xlDBF3)
>
>truncates the data. Is where a better way to import Excel of unknown structure?
>
>>I am using this:
>>
>>.....
>>ConnectionString="ODBC;DSN=Visual FoxPro Tables;UID=;PWD=;SourceDB=c:\;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;"
>>
>>sqlquery="SELECT * FROM c:\foxwork\vfpapps\syserr.dbf"
>>
>>ObjExcel.ActiveSheet.QueryTables.Add(;
>> ConnectionString,;
>> ObjExcel.ActiveSheet.Range("A1"),;
>> sqlquery).Refresh
>>....
>>
>>>I saw the answer to this awhile ago and thought I saved it for future reference....now the future is here and I can't find it!
>>>
>>>I am using the COPY TO command to export records to an Excel spreadsheet but I also need to export the text in the memo field for each record. I know there was a limit of 254 chars on the workaround, and that is fine.
>>>
>>>Can someone refresh my memory?
>>>
>>>tks,
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform