但问题是他总是打开一个下载框,现在名为consolo的文件(我的以上的代码就是封装在consolo.php)里的;我如果选则下载的话,就会下到一个叫consolo的文件,里面只有以上代码,没有我要的即时生成的$filename,请大虾们指点一下哦

解决方案 »

  1.   

    需要输出每个单元格的数据的呀。
    header("Content-type:application/vnd.ms-excel");
    header("Content-Disposition:filename=test.xls");include_once "Connect.inc.php";
    $link = new Connect();
    $sql = "select * from ftp";
    $array = $link->Execute($sql);
    echo "公司名称\t用户名\t密码\t端口\t\n";
    foreach($array as $row)
    {
    echo $row["company"]."\t".$row["usename"]."\t".$row["password"]."\t".$row["port"]."\t\n";
    }
      

  2.   

    好象还是不行是否要将consolo.php 改成consolo.xls??
      

  3.   

    无论如何不可能得到代码吧?除非你的php没有解析运行
      

  4.   

    echo ("aa");//显示为aa算不算被解析了呢??除非你的php没有解析运行,我觉得不是这个问题!
      

  5.   

    aa不是代码啊
    从程序来看,fopen/fwrite数据到一个文件是不正确的
    应该使用程序中那两个header,然后直接向客户端echo就可以了
      

  6.   

    <?php
    /*
     * Created on 2006-6-29
     *
     * To change the template for this generated file go to
     * Window - Preferences - PHPeclipse - PHP - Code Templates
     */
     
     
     class DataSource{
      private $action;
      private $game_kind;
      private $game_sequence;
     
      function DataSource($action,$game_kind,$game_sequence=null) {
      if($this->test_action_param($action)&&$this->test_game_kind_param($game_kind)){
      $this->action=$action;
      $this->game_kind=$game_kind;
     
      }
      if($this->test_game_sequence_param($game_sequence)){
      $this->game_sequence=$game_sequence;
      }
      }
     
      function fetch_table(){
      global $gDB;
     
      if($this->action=='team_info_download'){
      $query_str="SELECT * FROM actual_team_info WHERE game_kind={$this->game_kind}";
    $gDB->query($query_str);
    //var_dump($query_str);

    if($gDB->query_is_success()){

    $file_name="temp/$this->game_kind"."_".date('Ymd$Gis').".xls";
    $fp = fopen($file_name, "w");
                    
                    header("Content-type:application/vnd.ms-excel");
                 header("Content-Disposition:filename=$file_name");
                
                    
                    foreach($gDB->Record as $key => $value){
    echo "$key\t";//用echo了!!!!!!!
    //var_dump($value);
    if(fwrite($fp,"$key\t")===false){
    echo "写入错误:$formatted_path";
             exit;
    }
    }
    do{
    foreach($gDB->Record as $value){
    echo "$value\t";
    }
    }while($gDB->next_record());
    }
    else{
    echo('数据返回有误');
      exit();
    }

    fclose($fp);


                
                //echo($file_name);
    }
      else if($this->action=='team_info_upload'){
      //$query_str="INSERT INTO member_match_info_hist(game_kind,match_seq_no,member_id,price,point,team_name,point_detail,buyer_count,status) VALUES('{$game_kind}',$match_seq_no,$member_id,$price,$point,'{$team_name}','$point_detail',$buyer_count,'{$status}')";
    //$gDB->query($query_str);
      }
    }

    private function test_action_param($action){
    if($action=='team_info_download'||$action=='team_info_upload'){
    return true;
    }
    else{
      echo('动作选项参数有误');
      exit();
      }
    }

    private function test_game_kind_param($game_kind){
    if(in_array($game_kind,array(1,6,10,2,7,8,17,5,11))){
    return true;
    }
    else{
      echo('联赛类型选项参数有误');
      exit();
      }
    }

    private function test_game_sequence_param(){
    return true;
    }
     }
     
     
     
     
     
     
     require('../mywan/phplib/db_oci8.inc'); 
     $gDB = new DB_Sql();
     $gDB->User     = 'xxxxx';
     $gDB->Password = 'xxxxx';
     $gDB->Database = 'game50';
     
     $action=$_POST['action'];
     //echo $action;
     
     $game_kind=$_POST['game_kind'];
     $game_sequence=$_POST['game_sequence'];
     
     $data_source=new DataSource($action,$game_kind,$sequence);
     $data_source->fetch_table();
    ?>
    改了,还是老样子,那个写入(fwrite)应该没有关系吧.
    现在我用echo !
      

  7.   

    具体到你的class思路我很难介入
    给个短程序你参考<?php
    header("Content-type:application/vnd.ms-excel");
    header("Content-Disposition:filename=test.xls");
    echo "test1\t";
    echo "test2\t\n";
    echo "test1\t";
    echo "test2\t\n";
    echo "test1\t";
    echo "test2\t\n";
    echo "test1\t";
    echo "test2\t\n";
    echo "test1\t";
    echo "test2\t\n";
    echo "test1\t";
    echo "test2\t\n";
    ?>另外,个人建议你加上去缓存的header
    因为我试过在一个旧程序(曾经运行过)加上上述代码,用f5刷新也是输出text字串,在地址栏按回车才能输出excel,不知道你是不是这个问题
      

  8.   

    when you end writing the xls file,redirect to the file like:
    <script>
    window.open("test.xls");
    </script> or use header("location:test.xls");
      

  9.   

    楼上的大哥,我以上的代码只能生成一个consolo.xls的文件下载,要下载后双击打开;但不能自动打开.
      

  10.   

    header("Content-type:application/vnd.ms-excel");
    header("Content-Disposition:filename=consolo.xls");
    header("location:consolo.xls");无法重定向!