Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Export or Copy TO Excel and Date Formatting
Message
From
24/03/2009 12:09:40
 
 
To
23/02/2009 10:18:34
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01383448
Message ID:
01391055
Views:
130
Thanks Cetin and All for the replies.


>>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
In the End, we will remember not the words of our enemies, but the silence of our friends - Martin Luther King, Jr.
Previous
Reply
Map
View

Click here to load this message in the networking platform