Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Export or Copy TO Excel and Date Formatting
Message
De
04/03/2009 02:37:10
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01383448
Message ID:
01385395
Vues:
86
>>>Hi All
>>>
>>>When using COPY TO ... TYPE XL5 or EXPORT TO ... TYPE XL5 how can I ensure that dates are converted correctly and formatted as date fields in the target XLS file? Or is there another way?
>>>
>>>TIA
>>
>>You can't. The better way (and IMHO the correct way) is to use OLEDB instead. ie:
>>
Local oExcel
>>oExcel = Createobject("Excel.Application")
>>With oExcel
>>	.WorkBooks.Add
>>	.Visible = .T.
>>	VFP2Excel(_samples+'data\testdata.dbc',;
>>		'select * from orders',;
>>		.ActiveWorkBook.ActiveSheet.Range('A1'))
>>	.ActiveWorkBook.ActiveSheet.UsedRange.Columns.Autofit()
>>Endwith
>>
>>Function VFP2Excel
>>	Lparameters tcDataSource, tcSQL, toRange
>>	Local loConn As AdoDB.Connection, ;
>>		loRS As AdoDB.Recordset,;
>>		ix
>>	loConn = Createobject("Adodb.connection")
>>	loConn.ConnectionString = "Provider=VFPOLEDB;Data Source="+m.tcDataSource
>>	loConn.Open()
>>	loRS = loConn.Execute(m.tcSQL)
>>
>>	For ix=1 To loRS.Fields.Count
>>		toRange.Offset(0,m.ix-1).Value = Proper(loRS.Fields(m.ix-1).Name)
>>		toRange.Offset(0,m.ix-1).Font.Bold = .T.
>>	Endfor
>>	toRange.Offset(1,0).CopyFromRecordSet( loRS )
>>	loRS.Close
>>	loConn.Close
>>Endfunc
Cetin
>
>Hi Cetin,
>
>If I want to use a free table (the result of the select), how should I modify this code?
>
>Thanks again.

You shouldn't. Pass the folder of table as data source.
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