Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Single call to excel
Message
From
10/04/2007 13:32:14
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
09/04/2007 14:44:52
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
01213473
Message ID:
01214031
Views:
14
>>>I recall someone giving me advice on sending a batch of data to excel in a single call rather than sending each cell explicitly, but I am unable to locate my notes on the subject. Would someone indulge my lack of memory and organization and share that technique with me again?
>>>
>>>Thanks
>>
>>Something like this?
>>
>>VFP2Excel(_samples+'data\testdata.dbc','select * from customer',"Customers")
>>
>>function VFP2Excel
>>lparameters tcDataSource, tcSQL, tcSheetName
>>Local loConn As AdoDB.Connection, ;
>>	loRS As AdoDB.Recordset,;
>>	oExcel as Excel.Application
>>
>>loConn = Createobject("Adodb.connection")
>>loConn.ConnectionString = "Provider=VFPOLEDB;Data Source="+m.tcDataSource
>>loConn.Open()
>>loRS = loConn.Execute(m.tcSQL)
>>oExcel = Createobject("Excel.Application")
>>With oExcel
>>	.WorkBooks.Add
>>	.Visible = .T.
>>	With .ActiveWorkBook.ActiveSheet
>>		.Name = m.tcSheetName
>>		FOR ix=1 TO loRS.Fields.Count
>>			.Cells(1,m.ix).Value = PROPER(loRs.Fields(m.ix-1).Name)
>>		endfor
>>		.Range('A2').CopyFromRecordSet( loRS )
>>		.UsedRange.Rows(1).Font.Bold = .t.
>>		.UsedRange.Columns.Autofit
>>	Endwith
>>Endwith
>>loRs.Close
>>loConn.Close
>>
Cetin
>
>Cetin thanks!
>I was thinking it was either you or Borislav who help me before on this but this code sample does not look familiar. Is there a way to do it without the ado connection? How about the various formatting commands like borders, fonts, etc.?

Hmm there are N different ways to do this and this one is one the best if not the best:)
Formatting commands are straight forward. You get the range you want to format and set border object's properties. Also you could format based on conditions (like VFP's grid coloring).
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
Previous
Reply
Map
View

Click here to load this message in the networking platform