Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Import Excel data
Message
De
22/03/2007 12:21:38
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
01207090
Message ID:
01207147
Vues:
55
>>>Hi,
>>>
>>>Working on an Excel data extraction project. The Excel worksheet may have several sheets that all need to read data from.
>>>
>>>I've gotten to the the point where I need to know the sheet names to be used for the select statement for the InitRecordset.
>>>
>>>Here is my sample code:
>>>
>>>LOCAL oXLSConnect, oRecXLS, oXLSRS
>>>oXLSConnect = CREATEOBJECT('adodb.connection')
>>>oXLSConnect.cConnectionString = [Provider=Microsoft.Jet.OLEDB.4.0;Data Source=] ;
>>>	+ GETFILE() + [;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";]
>>>oXLSConnect.Open
>>>
>>>oRecXLS = CREATEOBJECT('veRecHandler')   && veRecHandler is an internal class we have
>>>lcSqlCmd = "select * from [" + TRIM(sheet_name) + "]"
>>>oXLSRS = oRecXLS.InitRecordSet(adUseClient, adOpenStatic, adLockOptimistic, lcSqlCmd, oXLSConnect)
>>>oRecXLS.Rs2Cusror(oXLSRS, "C_" + TRIM(table_name))
>>>
>>>
>>>
>>>Any help is greatly appreciated.
>>>
>>>Regards,
>>>Ariel
>>
>>
>>lcXLS = GETFILE("xls")
>>lcConn = "Driver={Microsoft Excel Driver (*.xls)};"+;
>>  "DriverId=790;Dbq="+m.lcXLS+;
>>  ";DefaultDir="+JustPath(m.lcXLS)+";"
>>lnHandle = SQLStringConnect(lcConn)
>>SQLTables(lnHandle,"", "SheetNames")
>>Scan
>>	lcTableName = Trim(SheetNames.Table_Name)
>>	lcOutput = Chrtran(m.lcTableName,' $','_')
>>	SQLExec(lnHandle,'select * from ['+m.lcTableName+']',m.lcOutput )
>>endscan
>>SQLDisconnect(lnHandle)
>>
Cetin
>
>Hi,
>
>Thanks for the reply. Considered that (already have code in another project that has it) but due to data types and formatting, had to use the method in my sample code.
>The mskb #194124 (http://support.microsoft.com/kb/194124/EN-US/) PRB: Excel Values Returned as NULL Using DAO OpenRecordset ) explains the issue when the column has mixed numeric and text values.
>
>Regards,
>Ariel

Ariel,
It doesn't matter one or the other way you can get sheetnames with 'table' on it.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform