分类
PHP

php导出excel

`public function excel_out(){

    $where = "id>1 ";

    //2.供应商uid
    $uid = req::item('uid');

    if($uid){
        $where .= "and uid=$uid ";
    }

    //供应商单独处理
    $pid = req::item('pid');
    if($pid){
        $where .= "and uid=$pid ";
    }

    //4.员工能查看的供应商集合(如果他进行筛选,跳过)
    $uids = req::item('uids');
    $uid = req::item('uid');
    if($uids && !$uid){
        $where .= "and uid in ($uids) ";
    }

    //5.下单时间
    $start = req::item('start');
    if($start){
      $where .= "and createtime>='$start' ";
    }

    $end = req::item('end');
    if($end){
      $where .= "and createtime<='$end' ";
    }

    //每页记录数量
    $sql = "SELECT * FROM ffsm_orders where $where order by createtime desc limit 0,100";

    $filename="time().xls";//先定义一个excel文件
    header("Content-Type: application/vnd.ms-execl");
    header("Content-Type: application/vnd.ms-excel; charset=utf-8");
    header("Content-Disposition: attachment; filename=$filename");
    header("Pragma: no-cache"); header("Expires: 0");
     //我们先在excel输出表头,当然这不是必须的
    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", "解锁状态")."\n";

    db::query('set names utf8');
    $result=db::query($sql); //查询的表条件
    $rows=db::fetch_all($result);

    $arrtype = [
                '31' => '塔罗牌-三个月内你会脱单吗?',
                '32' => '塔罗牌-你能和前任复合吗?',
                '28' => '塔罗牌-ta的心里有没有你?',
                '29' => '塔罗牌-你和ta该继续吗?',
                '34' => '塔罗牌-你和ta该分手吗?',
                '33' => '塔罗牌-你和ta能走到最后吗?',
                '35' => '塔罗牌-ta心理有别人吗?',
                '3' => '姓名详批',
                '12' => '2020流年运程',
                '26'=>'未来运势大揭秘'
            ];

    foreach($rows as $key=>$row){

       echo iconv("utf-8", "gb2312", "[".$row['oid']."]")."\t";
       echo iconv("utf-8", "gb2312", $arrtype[$row['type']])."\t"; 
       echo iconv("utf-8", "gb2312", "[".$row['oid']."]")."\t";

       echo iconv("utf-8", "gb2312", $row['createtime'])."\t";

       echo iconv("utf-8", "gb2312", $row['money'])."\t";

       if($row['status']==1){
         $status="已解锁";
       }else{
         $status="未解锁";
       }
       echo iconv("utf-8", "gb2312", $status)."\n"; 

   }
}`

发表评论

电子邮件地址不会被公开。 必填项已用*标注