菜鸟提问关于PHP导出EXCEL问题

我想将两个日期之间的搜索结果导出为EXCEL。下面是导出的程序,但是到处完毕以后,所有数据都在EXCEL表格中第一行A列的第一个格中,请问应该怎么解决???谢谢!!!!!!!!!!!!!!!!

<?php
session_start();
require_once("function.php");
checkuser();
$filename="ts.xls";//先定义一个excel文件
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 》
<html >
<head>
<title>投诉信息导出</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<?php
$uname=$_SESSION["loginname"];
                    $ulevel=$_SESSION['level'];
     $conn=mysql_connect("localhost","root","root") or die("数据库服务器连接错误".mysql_error());
     mysql_select_db("yiyuan",$conn) or die("数据库访问错误".mysql_error());
     mysql_query("set names gb2312");
     $sql="select unit from usertable where name='$uname';";
                    $result=mysql_query($sql,$conn);
                    $row=mysql_fetch_row($result);
                    mysql_free_result($result);
                    $unit=$row[0];//得到登录用户单位
                    //echo "unit=$unit";
     $date1=$_POST[date1];
     $date2=$_POST[date2];
     //echo "date=$date1";
     //echo "date=$date2";
    
echo "日期"."\t";
echo "投诉人姓名"."\t";
echo "联系方式"."\t";
echo "工作单位"."\t";
echo "被投诉人姓名"."\t";
echo "所属科室"."\t";
echo "投诉性质"."\t";
echo "录入科室"."\t";
echo "投诉内容"."\t";
echo "处理结果"."\n";
$res = mysql_query("select * from tousu where date <= '$date2' and  date>='$date1' order by date asc  ");

while($row =mysql_fetch_array($res)){
echo $row['date']."\t";
echo $row['name1']."\t";
echo $row['tel']."\t";
echo $row['company']."\t";
echo $row['name2']."\t";
echo $row['united']."\t";
echo $row['nature']."\t";
echo $row['unit']."\t";
echo $row['neirong']."\t";
echo $row['jieguo']."\n";
}
?>
</body>
</html>

作者: featherill   发布时间: 2011-09-01

//一个例子

<?php
Header( "Content-type:   application/octet-stream ");
Header( "Accept-Ranges:   bytes ");
Header( "Content-type:application/vnd.ms-excel ");  
Header( "Content-Disposition:attachment;filename=test.xls ");
$con = mysql_connect("localhost","root","");
mysql_select_db("plane");
mysql_query('set names utf8');
$sql = "select id,title,content from t_news";
$result = mysql_query($sql,$con);
echo "id\ttitle\tcontent";
while ($rs=mysql_fetch_array($result)){
echo "\n";
echo $rs['id']."\t".$rs['title']."\t".$rs['content'];
}

作者: 白老师   发布时间: 2011-09-01

<?php
/**
* Excel导出数据
*
* 创建日期 : 2011-9-1 11:31
* @author Wu Bai Qing<wbqyyicx@gmail.com>
*/
header("Content-Type: application/vnd.ms-execl");  
header("Content-Disposition: attachment; filename=wbq.xls");  
header("Pragma: no-cache");  
header("Expires: 0");  

$array_list = array('姓名:'=>'吴佰清','年龄:'=>20);

?>

<table width="20%">
    <tr>
        <td>第一个格子</td>
        <td>
        <?php
            foreach($array_list as $key => $val)
            {
                echo $key.$val;
            }
        ?>
        </td>
    </tr>
</table>

作者: 叶子   发布时间: 2011-09-01