RE: [PHP] Excel problem
| From: | Brad Fuller | Date: | Thu, 16 Nov 2006 19:38:26 +0000 |
| Subject: | RE: [PHP] Excel problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-244738@lists.php.net to get a copy of this message | ||
<?php
$query = "SELECT ....";
$result = mysql_query($query);
header ("Content-Type: application/octet-stream");
header ("Content-Disposition: attachment; filename=whatever.xls");
echo "Field1\tField2\r\n"; // Column names
while($row = mysql_fetch_array($result)) {
echo $row['field1'] . "\t" . $row['field2']. "\r\n"; //
Data
}
?>
You could also name the file *.csv and use a comma as a delimiter instead.
Don't forget to put quotes around any data that may have tab characters in
it. (Or commas if you're using csv)
Hope that helps
-B
> -----Original Message-----
> From: amit hetawal [mailto:amit.hetawal@gmail.com]
> Sent: Thursday, November 16, 2006 2:26 PM
> To: php-general@lists.php.net
> Subject: [PHP] Excel problem
>
> Hello all,
> Am pretty new to the world of PHP. And am now stuck.
> Its like i am displayin the data from a database on to my webpage in
> the form of tables.
> but now i also want an option for the user to download the above data
> into an excel format for the offline use. I dont want to create the
> excel file for each of the webpage i am displaying as they are all
> dynamic so there can be many.
> is there a way so that only if user click the given link at the bottm
> of the page then only the data is transferred to excel.
> i.e how to i write the displayed data dynamically to the excel without
> storing anything on the server.
> I am able to config the pear:excelwriter but dont know hwo to get it
> working according to my requirements.
>
> please advice.
>
> thanks
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>