2007年10月25日星期四

用PHP生成excel

<?php
ob_start();
define("FILETYPE","xls");

header("Content-type:application/vnd.ms-excel");
if(FILETYPE=="xls")
header("Content-Disposition:filename=report.xls");
else
header("Content-Disposition:filename=report.csv");

//逗号分隔值文件
/*
echo "姓名,年龄,性别\n";
//echo "efg\t\hij\t\n";
echo "张三,25,male";
echo "\n李四,27,male";
echo "\n王五,20,female";
*/
//xls file

echo "姓名\t年龄\t性别\n";
//echo "efg\t\hij\t\n";
echo "张三\t25\tmale";
echo "\n李四\t27\tmale";
echo "\n王五\t20\tfemale";
?>

没有评论: