Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Incorporating Excel

Status
Not open for further replies.

bebbo

Programmer
Dec 5, 2000
621
GB
I have a table which holds membership information. This information needs extracting into an Excel Spreadsheet. Presently this is achieved by extracting this table into a txt file then opening Excel and opening this text file within Excel. Is there a way this can be achieved within a Foxpro program without seperately opening Excel. If not surely there is an easier way to extract data into Excel???
 
You should try

EXPORT TO FILENAME.XLS TYPE XLS

It should be easyer.
Good Luck!
 
SELECT myTable
COPY to myExcel TYPE XLS (XL5)

Or you could automate the whole process, if you need proper formatting
 
Thanks

I've know been told that the operator has got to be able to select what fields should be exported. Is there an easy way just to export certain fields and allow the operator to pick these fields???
 
Both COPY TO and EXPORT support a list of Fields. Just store the field names in a character variable, and include a macro to expand them in the command. e.g.

lcFields = "Name, SSNO, Data1"
EXPORT TO FILENAME.XLS TYPE XLS FIELDS &lcFields

Rick
 
Thanks

That has worked like a treat. One little thing the filds headings appear on the first line of the Excel file. Is it possible to remove this line or even better is it possible to have these as the Excel headings (i.e. Firstname instead of A, Secondname instead of B, etc.....).
 
Not automatically... you could:

EXPORT TO the export file
loEx = CREATEOBJECT('excel.application')
use loEx to open the file
automate through loEx to set the headings and remove the first row.
 
Yes you can will take one more step but should be quite easy.

Use a select statement to select the fields you want then export the query to Excel as stated above

select field1 as LastName, field2 as FirstName, field3 as City into cursor newtable

select newtable

export to filename.xls type xls(5)

This will extract the fields you ask for plus change the Headings so they are easier to work with.

 
If you "copy fields x,y,z to output.csv type delim" the file will proably be set to open with Excel (it seems to register itself as master of the 'csv' extension) and there will be no headers.

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top