下载excel和 时不起作用


While downloding excel and is not working

我编写了下载excel文件的代码。这就是我给出的标题和数据。但是我的标题没有被分成标签。它只在一个选项卡中(在一列中)。请参考m代码。

$res = mysql_query($sql);
    $header = "Sr No. 't Team Member Name 't Profile Name 't Email Id. 't Guys Count 'tGirls Count 'tNo.paid guys 'tNo.paid girls 't Guest Count";

    while ($row_gl = mysql_fetch_assoc($res))
    {
            $sr_no = str_replace('"', '""', $count);
            $sr_no = '"' . $sr_no . '"' . "'t";
            $line .= $sr_no;
            if (empty($row_gl['ds_comments']))
            {
                $gl_count = str_replace('"', '""', "NA");
                $gl_count = '"' . $gl_count . '"' . "'n";
                $line .= $gl_count;
            }
            else
            {
                $gl_count = str_replace('"', '""', $row_gl['ds_comments']);
                $gl_count = '"' . $gl_count . '"' . "'n";
                $line .= $gl_count;
            }
            $count++;    
    }
    $name = date('d-m-y');
    //header("Content-type: application/octet-stream");
    header("Content-type:application/vnd.ms-excel;name='excel'");
    header("Content-Disposition: attachment; filename=".$name. ".xls");
    header("Pragma: no-cache");
    header("Expires: 0");
    // Output data
    echo $header . "'n'n" . $data;

您有没有想过用逗号分隔并创建CSV?

就我个人而言,我会使用一个现有的PHP到Excel库或CSV来做类似的事情。