Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. sponsors. rss.
 From: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
 To: Patrick McGreevy
  Where is Patrick McGreevy?
 Clarksville
 Tennessee - United States
 Patrick McGreevy
 Tags
Subject: RE: Automation with Excel 2007
Thread ID: 164549 Message ID: 164633 # Views: 47 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Microsoft Office Automation
Date: Wednesday, March 19, 2008 2:38:01 PM         
   


>
> Thanks, but no thanks. Everyone here is still running Office 2003.
>
> Pat

Probably I wasn't clear:) Then it'd be saved as Excel2003. ie:

#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


Instead of visible = .t. you could do:

.DisplayAlerts = .F.
*...
.ActiveWorkbook.SaveAs(m.lcFileNameFullpath)
.Quit


Cetin Basoz



COMPLETE THREAD
Automation with Excel 2007 Posted by Patrick McGreevy @ 3/19/2008 1:46:39 AM
RE: Automation with Excel 2007 Posted by Borislav Borissov @ 3/19/2008 8:47:43 AM
RE: Automation with Excel 2007 Posted by Patrick McGreevy @ 3/19/2008 2:36:16 PM
RE: Automation with Excel 2007 Posted by Cetin Basoz @ 3/19/2008 11:29:02 AM
RE: Automation with Excel 2007 Posted by Patrick McGreevy @ 3/19/2008 2:30:58 PM
RE: Automation with Excel 2007 Posted by Cetin Basoz @ 3/19/2008 2:38:01 PM
RE: Automation with Excel 2007 Posted by Patrick McGreevy @ 3/20/2008 6:35:13 PM
RE: Automation with Excel 2007 Posted by Anders Altberg @ 3/19/2008 2:54:08 PM
RE: Automation with Excel 2007 Posted by Patrick McGreevy @ 3/20/2008 6:50:18 PM
RE: Automation with Excel 2007 Posted by David Jo @ 8/5/2009 5:32:35 PM
RE: Automation with Excel 2007 Posted by Cetin Basoz @ 8/5/2009 6:51:13 PM
RE: Automation with Excel 2007 Posted by David Jo @ 8/5/2009 7:26:29 PM
RE: Automation with Excel 2007 Posted by Borislav Borissov @ 8/5/2009 8:07:00 PM
RE: Automation with Excel 2007 Posted by Anders Altberg @ 8/5/2009 9:45:50 PM