Thinkphp 匯出大量資料 csv格式

來源:互聯網
上載者:User

標籤:編號   utc   匹配   rtm   str   elm   logs   cli   span   

public function test2() {        $user_count = M(‘department‘)->count();        $page = ceil($user_count / 10000);        $fp = fopen(‘c:\file.csv‘, ‘w‘);        for ($p = 1; $p <= $page; $p++) {            $user = M(‘department‘)->page($p . ‘,10000‘)->select();            foreach ($user as $fields) {                foreach ($fields as $i => $v) {                    $fields[$i] = iconv(‘utf-8‘, ‘gbk‘, $v);                }                fputcsv($fp, $fields);            }            unset($user);        }        fclose($fp);    }

 

 

public function exportseller($begindate = ‘‘, $enddate = ‘‘, $areaid = 0, $search = ‘‘) {        ini_set(‘memory_limit‘,‘1024M‘);        set_time_limit ( 0 );        $where = array (); // 篩選條件集合        $areaid = session ( ‘authority‘ ); // 地區經理角色限定查看地區        // 選擇起止時間後,才顯示記錄        if (isset ( $_GET [‘begindate‘] ) && isset ( $_GET [‘enddate‘] )) {            $begindate = I ( ‘get.begindate‘ );            $enddate = I ( ‘get.enddate‘ );            $begindate .= " 00:00:00";            $enddate .= " 23:59:59";            $where [‘r.createtime‘] = array (                ‘between‘,                array (                    $begindate,                    $enddate                )            );            if (FALSE === empty ( $_GET [‘search‘] )) {                $search = I ( ‘get.search‘ );                $where [‘i.user‘] = array (                    ‘like‘,                    ‘%‘ . $search . ‘%‘                );            }            if ($areaid > 0) {                $where [‘s.id_area‘] = $areaid;            } elseif (FALSE === empty ( $_GET [‘areaid‘] )) {                $areaid = I ( ‘get.areaid‘ );                $where [‘s.id_area‘] = $areaid;            } else {            }            $record = D ( ‘Record‘ );            $xlsCell = array (‘comp‘=>‘所屬公司‘,‘sellername‘=>‘姓名‘,‘sellermobile‘=>‘手機號‘,‘sellerjob‘=>‘崗位‘,‘shopno‘=>‘店鋪編號‘,‘shopname‘=>‘店鋪名稱‘,‘areaname‘=>‘所屬市場‘,‘prodname‘=>‘商品名稱‘,‘sellerjifen‘=>‘積分‘,‘seltime‘=>‘銷售時間‘,‘wuliu‘=>‘物流碼‘,‘jfcd‘=>‘積分碼‘,‘card_num‘=>‘銀行卡號‘,‘FGoodsCode‘=>‘產品編號‘,‘FGoodsName‘=>‘產品名稱‘,‘FBillDate‘=>‘出入庫時間‘,‘FClientCode‘=>‘經銷商編號‘,‘FClientName‘=>‘經銷商名稱‘,‘istoo‘=>‘是否匹配‘);            $list = $record->sellerReport ( $where );            foreach ( $list as $i => $row ) {                $webdata=M(‘WebserviceData‘);                $map[‘box_code‘]=array(‘eq‘,$row[‘wuliu‘]);                $arr=$webdata->where($map)->find();                //$arr = $this->webServerData ( $row [‘wuliu‘] );                $row [‘FGoodsCode‘] = $arr [‘FGoodsCode‘];                $row [‘FGoodsName‘] = $arr [‘FGoodsName‘];                $row [‘FBillDate‘] = $arr [‘FBillDate‘];                $row [‘FClientCode‘] = $arr [‘FClientCode‘];                $row [‘FClientName‘] = $arr [‘FClientName‘];                $row [‘istoo‘] = $arr [‘FClientCode‘] == $row [‘shopno‘] ? ‘匹配‘ : ‘不匹配‘;                $str[$i]=array_iconv($row);            }            array_unshift($str,array_iconv($xlsCell));            header ( "Content-type:application/vnd.ms-excel" );            header ( "Content-Disposition:filename=" . iconv ( "UTF-8", "GB18030", "美容師統計報表".date(‘_YmdHis‘) ) . ".csv" );            $fp = fopen(‘php://output‘, ‘a‘);            foreach ($str as $key=>$line)            {                fputcsv($fp,$line);            }            fclose($fp);//            \Admin\Model\ExcelModel::exportExcel ( ‘美容師統計報表‘, $xlsCell, $list );        }        die();        //end modify        $this->display();    }

 

Thinkphp 匯出大量資料 csv格式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.