$filename="财务汇总.xls";
header("Content-Type: application/vnd.ms-excel");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("content-disposition: attachment;filename=".$filename);
echo <<<EOT
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP output Excel Example</title>
</head>
<table width="100%" border="1">
<tr>
<th>学号</th>
<th>姓名</th>
<th>辅修总学分</th>
<th>收费标准</th>
<th>应缴费金额</th>
<th>备注</th>
</tr>
EOT;
for($j=0; $j<$countnow; $j++){
echo "<tr>";
echo "<td>".$inf[$j]['number']."</td>";
echo "<td>".$inf[$j]['name']."</td>";
echo "<td>".$inf[$j]['total']."</td>";
echo "<td>"."115元/学分"."</td>";
echo "<td>".$inf[$j]['smoney']."</td>";
echo "<td>"." "."</td>";
echo "</tr>";
}
echo "</table>";excelheader
header("Content-Type: application/vnd.ms-excel");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("content-disposition: attachment;filename=".$filename);
echo <<<EOT
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP output Excel Example</title>
</head>
<table width="100%" border="1">
<tr>
<th>学号</th>
<th>姓名</th>
<th>辅修总学分</th>
<th>收费标准</th>
<th>应缴费金额</th>
<th>备注</th>
</tr>
EOT;
for($j=0; $j<$countnow; $j++){
echo "<tr>";
echo "<td>".$inf[$j]['number']."</td>";
echo "<td>".$inf[$j]['name']."</td>";
echo "<td>".$inf[$j]['total']."</td>";
echo "<td>"."115元/学分"."</td>";
echo "<td>".$inf[$j]['smoney']."</td>";
echo "<td>"." "."</td>";
echo "</tr>";
}
echo "</table>";excelheader
这是啥东东?你设置header以后,再输出html??
你这样做的话,你使用 hexview打开,你会看到,你后面的HTML代码全被写进了xls文件