我感觉不是EXCEL版本的问题,因为我输出的文件没有表格线,一片白,是不是输出格式不对?

解决方案 »

  1.   

    "\t"换"\r\n",给个例子你参考,我写的$csv = "1,2,3,4\r\n";
    $csv.= "1,";
                    $csv.= "2,";
                    $csv.= "3,";
                    $csv.= "中文,";
                    $csv.="\r\n";
                    $csvStr .= iconv("UTF-8","GBK//IGNORE",$csv);
                    $csv='';
    header("Content-type: application/octet-stream");
            header("Accept-Length: ".strlen($csvStr));
    header("Content-Disposition: attachment; filename=userrank_".date('ymd')."csv");
    echo $csvStr;
      

  2.   


    //给你个例子参考
    <?php
    function aircity($code){
    $sql="select * from aircity where threema='$code'";
    $r=mssql_query($sql);
    $rs=mssql_fetch_object($r);
    $city=trim($rs->city);
    return $city;
    }$id=join(',',$_POST['id']);//echo $id."<br>";
      $aa=explode(',',$id);
      foreach($aa as $v){
       $bb=explode('~',$v);
       $i=1;
       foreach($bb as $vn){
       if($i==1){
       $gg_id.=$vn."|";
       }
       $i++;
       }
      
      
      }
      //echo $gg_id; if($cjr==""){
    echo iconv("utf-8","gb2312","订单编号")."\t";
    echo iconv("utf-8","gb2312","预定日期")."\t";
    echo iconv("utf-8","gb2312","会员名")."\t";
    echo iconv("utf-8","gb2312","预订人")."\t";
    echo iconv("utf-8","gb2312","机票航程")."\t";
    echo iconv("utf-8","gb2312","起飞日期")."\t";
    echo iconv("utf-8","gb2312","航班号")."\t";
    echo iconv("utf-8","gb2312","票面价")."\t";
    echo iconv("utf-8","gb2312","税收")."\t";
    echo iconv("utf-8","gb2312","出票状态")."\t";
    echo iconv("utf-8","gb2312","总价")."\t";
    echo "\n";
      $detail=explode('|',$gg_id);
      foreach($detail as $sid){
      if($sid!=""){
    $sql="select * from pnrdetail where sid='$sid'";
    //echo $sql;
    $r=mssql_query($sql);
    $rs=mssql_fetch_object($r);
    $sid=$rs->sid;
    $id=$rs->id;
    //$memberid=$rs->memberid;
    $kefu=$rs->kefu;
    $username=$rs->username;
    $Pnr=$rs->Pnr;
    $pnum=$rs->pnum;
    $cjr=$rs->cjr;
    $hc=$rs->hc;
    $hb=$rs->hb;
    $qfdate=$rs->qfdate;
    $cw=$rs->cw;
    $price=$rs->price;
    $shui=$rs->shui;
    $kou=$rs->kou;
    $bymoney=$rs->bymoney;
    $jinprice=$rs->jinprice;
    $stype=$rs->stype;
    $content=$rs->content;
    $sdate=$rs->sdate;
    $stime=$rs->stime;
    $cwkou=$rs->cwkou;
    $printnum=$rs->printnum;
    $qj=$rs->qj;
    $chahc=$rs->chahc;
    $bxprice=$rs->bxprice;
    $dtotal=$rs->dtotal;
    $total_dtotal+=$rs->dtotal;
      
    echo $sid."\t";
    //echo $id."\t";
    echo date("Y-m-d",strtotime($sdate))."\t";
    echo $username."\t";
    //echo $Pnr."\t";
    //echo $pnum."\t";
    echo $cjr."\t";
    //echo $chianses."\t";
    $hcPost=explode("|",$hc);
      foreach($hcPost as $v){
      echo aircity(substr($v,0,3))."-".aircity(substr($v,3,6))."|";
      }
    echo "\t";
    echo $qfdate."\t";
    echo $hb."\t";
    //echo $cw."\t";
    echo $price."\t";
    echo $shui."\t";
    echo $stype."\t";


    echo $dtotal."\t";
    echo "\n";
    //echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\n";
    //
      }//if
    }//循环
    }//if($cjr==""){
    else{


    echo iconv("utf-8","gb2312","订单编号")."\t";
    echo iconv("utf-8","gb2312","预定日期")."\t";
    echo iconv("utf-8","gb2312","会员名")."\t";
    echo iconv("utf-8","gb2312","预订人")."\t";
    echo iconv("utf-8","gb2312","机票航程")."\t";
    echo iconv("utf-8","gb2312","起飞日期")."\t";
    echo iconv("utf-8","gb2312","航班号")."\t";
    echo iconv("utf-8","gb2312","票面价")."\t";
    echo iconv("utf-8","gb2312","税收")."\t";
    echo iconv("utf-8","gb2312","出票状态")."\t";
    echo iconv("utf-8","gb2312","总价")."\t";
    echo "总价\t";
    echo "\n";
    $detail=explode('|',$gg_id);
    foreach($detail as $sid){
    if($sid!=""){
    $sql="select * from pnrdetail where sid='$sid' order by sid desc ";
    //echo $sql."<br>";
    $r=mssql_query($sql);
    $rs=mssql_fetch_object($r);
    $sid=$rs->sid;
    $id=$rs->id;
    //$memberid=$rs->memberid;
    $kefu=$rs->kefu;
    $username=$rs->username;
    $Pnr=$rs->Pnr;
    $pnum=$rs->pnum;
    $cjr=$rs->cjr;
    $hc=$rs->hc;
    $hb=$rs->hb;
    $qfdate=$rs->qfdate;//起飞日期
    $cw=$rs->cw;
    $price=$rs->price;
    $shui=$rs->shui;
    $kou=$rs->kou;
    $bymoney=$rs->bymoney;
    $jinprice=$rs->jinprice;
    $stype=$rs->stype;
    $content=$rs->content;
    $sdate=$rs->sdate;
    $stime=$rs->stime;
    $cwkou=$rs->cwkou;
    $printnum=$rs->printnum;
    $qj=$rs->qj;
    $chahc=$rs->chahc;
    $bxprice=$rs->bxprice;
    $dtotal=$rs->dtotal;
    $total_dtotal+=$rs->dtotal;

      echo $sid."\t";
    //echo $id."\t";
    echo date("Y-m-d",strtotime($sdate))."\t";//substr($sdate,0,10)
    echo $username."\t";
    //echo $Pnr."\t";
    //echo $pnum."\t";
    echo $cjr."\t";
    //echo $chianses."\t";
    $hcPost=explode("|",$hc);
      foreach($hcPost as $v){
      echo aircity(substr($v,0,3))."-".aircity(substr($v,3,6))."|";
      }
    echo "\t";
    echo $qfdate."\t";
    echo $hb."\t";
    //echo $cw."\t";
    echo $price."\t";
    echo $shui."\t";
    echo $stype."\t";


    echo $dtotal."\t";
    echo "\n";
    //echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\t";
    // echo "\n";
    }

    }//循环
    }
    ?>
      

  3.   

    我看了别人的讲解,了解了我在PHp代码里引用了JS,所以才会这样,把所有的JS去掉,正常了,还是谢谢各位