1.下載php
https://github.com/JOakley77/CI-Excel-Generation-Librarygit
2.解壓,並複製 Excel.php, 找到項目的 libraries 文件夾粘貼,不是 sysm\libraries這個文件夾,若是沒有就新建一個,github
3.具體操做this
引用類庫spa
$this->load->library('Excel');
處理要導出數據日誌
$array = array(); $titles = array( iconv("UTF-8", "GBK", '登陸時間'), iconv("UTF-8", "GBK", '登陸IP'), ); foreach ($logs as $logsKey => $logsVal){ $array[] = array( iconv("UTF-8", "GBK", date('Y-m-d',$logsVal['time'])), iconv("UTF-8", "GBK", $logsVal['IP']), ); }
輸出(下載導出數據)excel
$this->excel->make_from_array($titles, $array);
本身瞎折騰get
自定義導出文件名稱it
$this->excel->filename = '-登錄日誌-'.date('Y-m-d');