>>>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