Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sending a memo field to Excel
Message
 
 
To
27/03/2009 17:53:18
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01391928
Message ID:
01391959
Views:
72
>Hi. I want to send a memo field (along with my .dbf data) to an Excel spreadsheet. Can I? and how?
>
>Thanks, Randy

Cetin BASOZ's code
#Define xlTop -4160
Local oExcel
oExcel = Createobject("Excel.Application")
With oExcel
  .WorkBooks.Add
  .Visible = .T.
  VFP2Excel(_samples+'data\testdata.dbc',;
    'select emp_id,first_name,last_name,CAST(CHRTRAN(notes,CHR(13),"") as M) as Notes from employee',;
    .ActiveWorkBook.ActiveSheet.Range('A1'))
    
  * This part is cosmetic  
  With .ActiveWorkBook.ActiveSheet
    .UsedRange.VerticalAlignment = xlTop && set all to top
    With .Columns(5)
      .ColumnWidth = 80 && 80 chars width
      .WrapText = .T.
    Endwith
    .UsedRange.Columns.AutoFit
    .UsedRange.Rows.AutoFit
  Endwith
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
Previous
Reply
Map
View

Click here to load this message in the networking platform