Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Export or Copy TO Excel and Date Formatting
Message
De
23/02/2009 10:18:34
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
23/02/2009 08:26:29
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:
01383471
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
Ç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