Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Anders Altberg
  Where is Anders Altberg?
 Uppsala
 Sweden
 Anders Altberg
 To: Anil S
  Where is Anil S?
 delhi
 India
 Anil S
 Tags
Subject: RE: Export to excel
Thread ID: 393505 Message ID: 393646 # Views: 49 # Ratings: 2
Version: Visual FoxPro 9 SP2 Category: Databases, Tables and SQL Server
Date: Saturday, December 21, 2013 12:47:55 AM         
   


> Good day to all :-)
>
> Experts please give me a single line query to export selected data to excel file.
> The query which can run in both vfp and sql server.
>
> Thanks and Regards,
> Anil

Hers's one where Exdel is automated to use its Querytables.Add() function with VFPOLEDB.DLL:
SELECT * FROM Orders 

Here's an example turning the Orders.DBF in the Northwind.dbc into a spreadsheet you can then save as whatever XLS or XLSX format your customers support.

LOCAL oExcel AS Excel.APPLICATION
LOCAL oBook AS Excel.Workbook
LOCAL oSheet AS OBJECT
oExcel = CREATEOBJECT("Excel.Application")
oBook = oExcel.Workbooks.ADD
oSheet = oBook.Worksheets(1)

* 'Create the QueryTable object.
LOCAL oQryTable AS OBJECT, sNorthwind AS STRING
sNorthwind = HOME(2) +;
[NORTHWIND\NORTHWIND.DBC]
oQryTable = oSheet.QueryTables.ADD ;
("OLEDB;Provider=VFPOLEDB.1;Data Source="+sNorthwind+";", ;
oSheet.RANGE("A1"),"Select * from Orders")
oQryTable.RefreshStyle = 2 && xlInsertEntireRows = 2
oQryTable.REFRESH(.F.)
oExcel.VISIBLE=.T.

-Anders

ENTIRE THREAD

Export to excel Posted by Anil S @ 12/19/2013 12:51:30 PM
RE: Export to excel Posted by Cetin Basoz @ 12/19/2013 1:11:14 PM
RE: Export to excel Posted by Tamar Granor @ 12/19/2013 10:22:58 PM
RE: Export to excel Posted by Anil S @ 12/20/2013 3:31:45 PM
RE: Export to excel Posted by Anders Altberg @ 12/21/2013 12:47:55 AM