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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

export foxpro tables to excel

Status
Not open for further replies.

axc25

Technical User
Feb 13, 2011
3
0
0
RO
Hello! i have one table with the fields: ID, city, client_name. I need to generate a .xls file for each city. For example if i have 100 cities i need to generate 100 xls files from one command. is this possible? thanx!
 
From one command? No.

However, if your "one command" can be DO MYPROGRAM, then yes.

Let me say up front that you can create MYPROGRAM many different ways. I present here only one.

Code:
  Select id, city, client_name ;
    from (yourtable) ;
    sort by city ;
    into cursor foo

   Select Foo
   Do While Not EOF()
      filename = Trim(foo.city)
      Copy To &filename TYPE XLS While Trim(foo.city) = filename
   Enddo
 
Dan,

I think a small error crept into your code.

Instead of this:

Code:
Copy To &filename TYPE XLS While Trim(foo.city) = filename

do this:

Code:
Copy To &filename TYPE XLS [b]FOR[/b] Trim(foo.city) = filename

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Yes, the typo is in the SELECT.

You wouldn't even need the SELECT if the original table carries an index on City. Just set order and use the same DO WHILE (doctoring for the different alias).

COPY TO ... FOR, in this context, wouldn't produce the right result unless you first produce a unique list of city values so the code would be written differently. I prefer the WHILE scope because the table (or cursor) is traversed in a single pass rather than requiring the in-memory bitmap construction of the FOR syntax on each COPY.
 
thank u very much both of u!!! it worked:)
 
See my FAQs for better formatted output, ability to make workbooks quickly and freedom from memo field limitations.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top