本文主要和大家分享php如何用header導出excel詳解,希望能幫助大家,我們先來看看範例圖。
這個是導出execl 按鈕
直接把查询条件,全部传值给另外一个连接
lists 是查詢的列表方法, excel 是導出方法, 把原來的方法呼叫一遍
#新增 2個header 程式碼 接著改寫view html 的檔案 就直接匯出了
function lists() { I("date") ? $this->date = I("date"):$this->date =date("Y-m"); $where = $this->query(); $model = M("project_sign"); $model->join("JOIN __PROJECT_USER__ on s_user_id = pu_id"); $model->join("JOIN __PROJECT_TEAM__ on s_team_id = t_id"); $model->join("JOIN __PROJECT__ on s_project_id = p_id"); $model->order("s_id desc"); $results = $model->where($where)->select(); $res = array(); foreach($results as $value) { if(!isset($res[$value['s_user_id']]['info'])) { $res[$value['s_user_id']]['info'] = $value; } if(!isset($res[$value['s_user_id']]['sign'])) { $res[$value['s_user_id']]['sign'] = array_pad(array(),32,""); unset($res[$value['s_user_id']]['sign'][0]); } $res[$value['s_user_id']]['sign'][$value['s_day']] = "是"; $res[$value['s_user_id']]['count']++; } $this->results = $res; $this->display(); } function excel() { header("Content-type: application/vnd.ms-excel; charset=utf8"); header("Content-Disposition: attachment; filename=filename.xls"); $this->lists(); }
由於匯出的excelcss 所以直接寫一個純表格的view
编号 | 姓名 | 工种 | <{$date}> | 合计 | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | ||||
<{$key}> | <{$value.info.pu_name}> | <{$value.info.t_name}> | <{$v}> | <{$value.count}> |
不用匯出後顯示
##相關推薦:
以上是php如何用header導出excel詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!