导出excel表

Posted llzhang123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了导出excel表相关的知识,希望对你有一定的参考价值。

<?php
public function export(){
      
    #提现状态
       
        $status = isset($_REQUEST[‘status‘])?$_REQUEST[‘status‘]:‘‘;
        $where="on mb.uid=wi.uid where ";
        if($status==1){
            $where.=" wi.status=1 ";
            $filename = ‘处理中申请记录‘;
            //处理中
        }elseif($status==2){
            //待转账
            $where.="wi.status=2 ";
            $filename = ‘待转账申请记录‘;
        }elseif($status==3){
            //已转账
            $where.="  wi.status=3 ";
            $filename = ‘已转帐申请记录‘;
        }elseif($status==4){
            //已拒绝
            $where.="  wi.status=4 ";
            $filename = ‘已拒绝申请记录‘;
        }else{
            $where.="1=1";
            $filename = ‘全部申请记录‘;
        }
        $type=isset($_REQUEST[‘type‘])?$_REQUEST[‘type‘]:‘1‘;
        $where.=" and type=‘$type‘ ";
        $posttime1 = isset($_REQUEST[‘posttime1‘])?$_REQUEST[‘posttime1‘]:null;
        $posttime2 = isset($_REQUEST[‘posttime2‘])?$_REQUEST[‘posttime2‘]:null;
        if($posttime1 && $posttime2){
            $where .= " AND `sq_time` > ‘$posttime1‘ AND `sq_time` < ‘$posttime2‘";
        }
        if($posttime1 && empty($posttime2)){
            $where .= " AND `sq_time` > ‘$posttime1‘";
        }
        if($posttime2 && empty($posttime1)){
            $where .= " AND `sq_time` < ‘$posttime2‘";
        }
        if(empty($posttime1) && empty($posttime2)){
            //$list_where = false;
        }
        
     $shoptype = isset($_REQUEST[‘shoptype‘])?$_REQUEST[‘shoptype‘]:null;
        $shopvalue = isset($_REQUEST[‘shopvalue‘])?htmlspecialchars(trim($_REQUEST[‘shopvalue‘])):null;
        if (!empty($shopvalue)) {
            switch ($shoptype) {
                case "id": //订单ID
                    if(isset($shopvalue) && $shopvalue!="0") $where .= " and wi.`id` = ‘".$shopvalue."‘";
                    break;
                case "uid": //用户id
                    if(isset($shopvalue) && $shopvalue!="0") $where .= " and wi.`uid` = ‘".$shopvalue."‘";
                    break;
                
                default:
                    ;
                    break;
            }
        }
        
        $recordlist=$this->db->GetList("SELECT wi.*,mb.money,mb.status as mbstatus FROM `@#_withdrawals` wi inner join `@#_member` mb $where");
        
        define(‘EC_CHARSET‘,‘utf-8‘);
        
        /* 文件名称 */
        if (EC_CHARSET == ‘gbk‘)
        {
            $filename = iconv(‘GBK‘, ‘UTF8‘,$filename);
        }
        
        header("Content-type: application/vnd.ms-excel; charset=utf-8");
        header("Content-Disposition: attachment; filename=$filename.xls");
        
        /* 文件标题 */
        if (EC_CHARSET == ‘gbk‘)
        {
            echo "<table border=‘1px‘>";
            echo "<tr>";
            echo "<td>". iconv(‘GBK‘, ‘UTF8‘, ‘唯一ID‘) . "</td>";
            echo "<td>".  iconv(‘GBK‘, ‘UTF8‘, ‘用户ID‘) ."</td>";
            echo "<td>" . iconv(‘GBK‘, ‘UTF8‘, ‘手机号码‘) ."</td>";
            echo "<td>" . iconv(‘GBK‘, ‘UTF8‘, ‘申请金额‘) ."</td>";
            echo "<td>" . iconv(‘GBK‘, ‘UTF8‘, ‘手续费‘) ."</td>";
            echo "<td>" . iconv(‘GBK‘, ‘UTF8‘, ‘应付金额‘) ."</td>";
            echo "<td>" . iconv(‘GBK‘, ‘UTF8‘, ‘真实姓名‘) ."</td>";
            echo "<td>" . iconv(‘GBK‘, ‘UTF8‘, ‘用户身份证号‘) ."</td>";
            echo "<td>" . iconv(‘GBK‘, ‘UTF8‘, ‘收款方式‘) ."</td>";
            echo "<td>" . iconv(‘GBK‘, ‘UTF8‘, ‘开户行‘) ."</td>";
            echo "<td>" .iconv(‘GBK‘, ‘UTF8‘, ‘开户支行‘) ."</td>";
            echo "<td>" .iconv(‘GBK‘, ‘UTF8‘, ‘银行卡卡号‘) ."</td>";
            echo "<td>" .iconv(‘GBK‘, ‘UTF8‘, ‘支付宝帐号‘) ."</td>";
            echo "<td>". iconv(‘GBK‘, ‘UTF8‘, ‘转账单号‘) ."</td>";
            echo "<td>" .iconv(‘GBK‘, ‘UTF8‘, ‘审核时间‘) ."</td>";
            echo "<td>" .iconv(‘GBK‘, ‘UTF8‘, ‘用户状态‘) ."</td>";
            echo "<td>" .iconv(‘GBK‘, ‘UTF8‘, ‘提现状态‘) ."</td>";
            echo "<td>" .iconv(‘GBK‘, ‘UTF8‘, ‘申请时间‘) ."</td>";
            echo "<td>" .iconv(‘GBK‘, ‘UTF8‘, ‘拒绝原因‘) ."</td>";
                echo "</tr>";
        }
        else
        {
            echo "<table border=‘1px‘>";
            echo "<tr>";
            echo"<td>". ‘唯一ID‘ . "</td>";
            echo"<td>". ‘用户ID‘ ."</td>";
            echo"<td>". ‘手机号码‘ ."</td>";
            echo"<td>". ‘提现金额‘ ."</td>";
            echo"<td>". ‘手续费‘ ."</td>";
            echo"<td>". ‘应付金额‘ ."</td>";
            echo"<td>". ‘真实姓名‘ ."</td>";
            echo"<td>". ‘用户身份证号‘ ."</td>";
            echo"<td>". ‘收款方式‘."</td>";
            echo"<td>". ‘开户行‘ ."</td>";
            echo"<td>". ‘开户支行‘ ."</td>";
            echo"<td>". ‘银行卡卡号‘ ."</td>";
            echo"<td>". ‘支付宝帐号‘ ."</td>";
            echo"<td>". ‘转账单号‘ ."</td>";
            echo"<td>". ‘审核时间‘ ."</td>";
            echo"<td>". ‘用户状态‘ ."</td>";
            echo"<td>". ‘提现状态‘ ."</td>";
            echo"<td>". ‘申请时间‘ ."</td>";
            echo"<td>". ‘拒绝原因‘ ."</td>";
                echo "</tr>";
        }
        
        $code_table = array();
        foreach ($recordlist as $key => $val)
        {
            echo "<tr>";
            echo "<td>".$val[‘id‘] . "</td>";
            echo "<td>".$val[‘uid‘] . "</td>";
            echo "<td style=‘vnd.ms-excel.numberformat:@‘>". $val[‘mobile‘]. "</td>";
            echo "<td>". $val[‘tx_money‘]. "</td>";
            echo "<td>".$val[‘poundage‘]. "</td>";
            echo "<td>". $val[‘amount_due‘]. "</td>";
            if (EC_CHARSET == ‘gbk‘)
            {
                $code_table[$val[‘name‘]] = iconv(‘GBK‘, ‘UTF8‘, $val[‘name‘]);
            }
            else
            {
                $code_table[$val[‘name‘]] = $val[‘name‘];
            }
            echo "<td>". $code_table[$val[‘name‘]] . "</td>";
            echo "<td style=‘vnd.ms-excel.numberformat:@‘>".$val[‘id_card‘]. "</td>";
            if($val[‘type‘]==1){
                echo "<td>"."银行卡收款</td>";
            }else{
                echo "<td>". "支付宝收款</td>";
            }
            echo"<td>". $val[‘bank_name‘]."</td>";
            echo  $val[‘branch‘]? "<td>".$val[‘branch‘]. "</td>":"<td>".‘空‘. "</td>";
            echo"<td style=‘vnd.ms-excel.numberformat:@‘>". $val[‘bank_card‘]. "</td>";
            echo"<td>". $val[‘accounts‘]. "</td>";
            echo"<td style=‘vnd.ms-excel.numberformat:@‘>". $val[‘transfer_number‘]. "</td>";
            echo $val[‘cz_time‘]? "<td>".date("Y-m-d H:i:s",$val[‘cz_time‘]). "</td>":"<td>".‘空‘. "</td>";
            if($val[‘mbstatus‘]==1){
                $mbstatus="黑名单用户";
            }
           else{
                $mbstatus="正常用户";
            }
            echo"<td>". $mbstatus. "</td>";
            if($val[‘status‘]==1){
                $status="处理中";
            }
            if($val[‘status‘]==2){
                $status="待转账";
            }
            if($val[‘status‘]==3){
                $status="已转账";
            }
            if($val[‘status‘]==4){
                $status="已拒绝";
            }
            echo"<td>". $status. "</td>";
            
            echo $val[‘sq_time‘]? "<td>".date("Y-m-d H:i:s",$val[‘sq_time‘]). "</td>":"<td>".‘空‘. "</td>";
            echo "<td>".$val[‘reason‘]. "</td>";
               echo "</tr>";
               
        }
        echo "</table>";
    }

?>

以上是关于导出excel表的主要内容,如果未能解决你的问题,请参考以下文章

如何把SQLServer表数据导出为Excel文件

如何把SQLServer表数据导出为Excel文件

js导出excel表如何保留小数点

arcgis插入excel导出无颜色

如何把SQLServer表数据导出为Excel文件

如何将mysql表结构导出成Excel格式的