你可以再执行一次SQL语句,把结果直接写到excel表中。下面是我以前做过的一个例子。可以往excel表中写内容。你可以参考一下。
##################################################
<?php
$mylink=mysql_connect("192.168.0.19","root","root");
mysql_select_db("IVR_RcdDB",$mylink);
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Content-type:application/vnd.ms-excel"); 
Header("Content-Disposition:attachment;filename=export_excel.xls"); 
$tx='省呼叫次数昨天、今天对比';
echo $tx."\n\n";
########################################
$p=0;
//>>>>>>>>>>>>>输出业务名
$sql_output="select count(*) as a,SpNum from IVR_TrffForm where 1=1 and StartTime>='".$date_from."' and StartTime<='".$date_to."' and SpNum<>'' group by SpNum order by a desc";
$result_output=mysql_query($sql_output,$mylink);
if(mysql_num_rows($result_output)>0){
echo "\t";
while($array_yh=mysql_fetch_array($result_output)){
echo $array_yh['SpNum'].'业务'."\t\t";
$p=$p+1;
}
}
echo "\n";
echo "\t";
?>