我的Excel报表都是这样生成的,请试试吧。
header("Content-type: application/zip");
header("Content-disposition: attachment; filename=$filename.xls");

解决方案 »

  1.   

    不行,我的还有[1]
    代码:
    <?php
    // 转载请注明phpteam
    $title = "数据库名:dzsw1, 数据表:hy_hy, 备份日期:" . date("Y-m-d H:i:s");
    $sep = "\t";
    $crlf = "\n";$con=@mysql_connect("localhost","root","root");
    $db=@mysql_select_db("dzsw1",$con) or die("不能连接数据库");
    header("Content-type: application/zip");
    header("Content-disposition: attachment; filename=$filename.xls");
    header("Pragma: no-cache");
    header("Expires: 0");echo $title . $crlf . $crlf;
    $v1="cpID";
    $v2="gsmc";
    $v4="cpmc";
    $query = "select ".$v1.",".$v2.",".$v4." from hy_hy,cp_cp where cp_cp.hyID=hy_hy.hyID";
    $result = mysql_query($query) or die(mysql_error());
    $fields = mysql_num_fields($result);
    for($i = 0; $i < $fields; $i++) {
    echo mysql_field_name($result, $i) . $sep;
    $zdbt=mysql_field_name($result, $i) ;
    if ($zdbt=="hyID"):
    $zdbt="会员序号";
    endif;
    if ($zdbt=="gsmc"):
    $zdbt="公司名称";
    endif;
    echo $zdbt. $sep;
    }
    echo $crlf;
    while($row = mysql_fetch_row($result)) {
        $line = "";
        for($i = 0; $i<$fields; $i++) {
            $line .= $row[$i] . $sep;
        }
        echo $line . $crlf;
    }?>运行后弹出对话框:
    文件名  :.xls[1]
    文件来自: XLS[1]文件
    来自    : 192.168.0.20怎么回事呀?
    谢谢!