Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Importing From CSV files not so simple
Message
De
29/05/2007 13:17:12
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
29/05/2007 10:56:50
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
01228989
Message ID:
01229109
Vues:
53
>I work with lowlevel file processing all of the time, but with these fields in Excel that have CR's & LF's I"m not sure what to look for to specify the end of the fields.
>
>So what I designate as a true field & record separate for a CSV file?
>
>Also, I've never used teh excel get data using oledb you speak of. Could you possibly give me a short example of that technique?
>
>Thanks -Rick
>
>>Rick,
>>You acan import by using lowlevel file processign or from excel get data using OLEDB.
>>Cetin

Having CRLF in a CSV doesn't fit to definition of a CSV in the first place.
Here is an OLEDB sample:
Local oRS As Adodb.recordset, oCon As Adodb.Connection
oCon = Createobject("adodb.connection")
oCon.ConnectionString = ;
    'Provider=Microsoft.Jet.OLEDB.4.0;'+;
    'Data Source="'+Sys(5)+Curdir()+[customer.xls]+;
    '";User ID=Admin;Password=;Extended properties=Excel 5.0'

oCon.Open
oRS = Createobject('AdoDB.Recordset')
With oRS
    .ActiveConnection=oCon
    .CursorLocation= 3  && adUseClient
*.CursorType= 2  && adOpenDynamic
*.LockType= 1  && adLockReadOnly
    oRS.Open('Select * from [customer$]')
Endwith
ShowMe("Excel result",oRS)
oCon.Close

Function ShowMe
Lparameters tcCaption,toRecordset
oForm = Createobject('myForm', tcCaption,toRecordset)
oForm.Show
Read Events
Endfunc

Define Class myform As Form
    Height = 450
    Width = 750
    Name = "Form1"

    Add Object hflex As OleControl With ;
        Top = 10, Left = 10, Height = 430, Width = 730, Name = "Hflex", ;
        OleClass = 'MSHierarchicalFlexGridLib.MSHFlexGrid'

    Procedure Init
    Lparameters tcCaption,toRecordset
    This.Caption = tcCaption
    This.hflex.Datasource = toRecordset
    This.hflex.AllowUSerResizing = 3
*  this.hFlex.FixedCols = 0
    Endproc
    Procedure QueryUnload
    Clear Events
    Endproc
Enddefine
And ODBC:
lcXLS = GETFILE("xls") 
lcConn = "Driver={Microsoft Excel Driver (*.xls)};"+;
  "DriverId=790;Dbq="+m.lcXLS+;
  ";DefaultDir="+JustPath(m.lcXLS)+";" 
lnHandle = SQLStringConnect(m.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
Ç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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform