Good stuff to know!  Thx, Geir!

Mark

-----Original Message-----
From: Geir Pedersen - Activio AS [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 24, 2004 9:05 PM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Re: exporting data to excel



Matthew,

> I am looking for the easiest way to export data to an excel file. Is
> the eaiest way to use PHP's file handling functions?

I assume you want to delivery the execl file to a web user.
Then there is no need to write the data to disk, you can
generate the whole thing on the fly while you deliver it to the
user. Here is a basic description on how:

1) Create a PHP document to generate the execl file and make
   sure the script produces HTTP headers telling the user agent
   that it is receiving an excel document. Start the script
   with:

      header ("Content-type: application/vnd.ms-excel");
      header ("Content-Disposition: attachment" );

   The content disposition header says that the execl file is
   to be stored on disk. 

2) Generate the spreadsheet data as a list of newline separated
   rows with tab separated fields:

   echo "field1\tfield2\t...\n";

3) Set up a link to the new PHP document. When a user clicks on
   that link, he will be prompted by his user agent on where to
   save the excel file.


---

Geir Pedersen
http://www.activio.com/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to