RE: Excel problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



<?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@xxxxxxxxx]
> Sent: Thursday, November 16, 2006 2:26 PM
> To: php-general@xxxxxxxxxxxxx
> Subject:  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
> 

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux