Skip to content


Generating Excel using PHP

require_once "excel.php";
$filename = "anyoneyoulike.xls";
$export_file = 'xlsfile:/tmp/'.$filename;
$fp = fopen($export_file, "wb");
if (!is_resource($fp))
{
die("Cannot open $export_file");
}
$assoc = array(
array("First name" => "Mattias", "IQ" => 250,
array("First name" => "Tony", "IQ" => 100,
array("First name" => "Peter", "IQ" => 100,
array("First name" => "Edvard", "IQ" => 100));
fwrite($fp, serialize($assoc));
fclose($fp);

Begin the download

header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ("Content-type: application/x-msexcel");
header ("Content-Disposition: attachment; filename=\"" . $filename . "\"" );
header ("Content-Description: PHP/INTERBASE Generated Data" );
readfile($export_file);
exit;

Posted in SmartPolice. Tagged with , , .

One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Hi, blog.mrcongwang.com to GoogleReader!
    SonyaSunny

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.