导出csv文件

function outexcel(){
    $head = array('交易编号','买入日期','客户姓名','手机号');
    $list = array();
    $trading_list = json_decode($_POST['trading_list'],true);
    foreach ($trading_list as $key => $value) {
        $value = $value['Trading'];
        $tmp = array();
        $tmp[]= $value['id'];
        $tmp[]= $value['created'];
        $tmp[]= $value['name'];
        $tmp[]= $value['tel'];
    }
    $this->_out_csv($head, $list, '交易列表');die;
}
    function _out_csv($head,$list,$filename){
        $this->autoRender = false;
        header("Content-Disposition:attachment;filename=".$filename.".csv"); 
        header('Content-Type: text/csv; charset=GB2312');

        $strexport = implode(",", $head);
        $strexport .= "\r";
        
       foreach ($list as $row){    
            $strexport .= implode(",", $row);
            $strexport .= "\r";
        }  
        $strexport=iconv('UTF-8',"GBK",$strexport);      
        exit($strexport);       
    }  

 

posted on 2017-11-03 10:16  薇薇123456  阅读(206)  评论(0编辑  收藏  举报

导航