Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Export or Copy TO Excel and Date Formatting
Message
 
 
À
23/02/2009 10:18:34
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:
01385351
Vues:
121
>>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.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform