php导出Excel表格(无插件)

public function tui_export(){
        if(empty($_GET['userid'])){
            showmessage('参数传递错误', '?m=weixin&c=recommend_list&a=index',2000);
        }
        $table="co_weixin_coupons` as cp LEFT JOIN co_cacos as c ON cp.userid=c.`userid";
        $where="cp.type=2 AND cp.userid={$_GET['userid']}";
        $infos=$this->coupons_db->select($where,'cp.*,c.cc_name','','cp.c_time DESC','','',$table);
        if(empty($infos)){
            showmessage('数据为空,不可导出!!!','?m=weixin&c=recommend_list&a=index',1000);
        }
        $data = array();
        foreach($infos as $k=>$v){
            $data[$k]['cc_name'] 		= $v['cc_name'];
            $data[$k]['money'] 		= $v['money']."元";
            $data[$k]['c_time'] 		= date("Y-m-d H:i:s",$v['c_time']);
            $data[$k]['status'] 		= $v['status']==2 ? "已发送红包" : "";
        }
        $title=array('姓名','红包金额','创建时间','状态');
        header("Content-type:application/octet-stream");
        header("Accept-Ranges:bytes");
        header("Content-type:application/vnd.ms-excel; charset=UTF-8");
        header("Content-Disposition:attachment;filename=".iconv("UTF-8", "GB2312//IGNORE",date('Y-M-D',time())."导出方案记录").".xls");
        header("Pragma: no-cache");
        header("Expires: 0");
        //导出xls 开始
        if (!empty($title)){
            foreach ($title as $k => $v) {
                $title[$k]=iconv("UTF-8", "GB2312//IGNORE",$v);
            }
            $title= implode("\t", $title);
            echo "$title\n";
        }
        if (!empty($refInfo)){
            foreach($refInfo as $key=>$val){
                foreach ($val as $ck => $cv) {
                    $refInfo[$key][$ck]=iconv("UTF-8", "GB2312//IGNORE", $cv);
                }
                $refInfo[$key]=implode("\t", $refInfo[$key]);
            }
            echo implode("\n",$refInfo);
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值