PHP导出Excel
时间:2015-05-28 阅读:次 QQ群:182913345
一个简单的PHP导出Excel类,简单易读,希望能帮助各位,代码如下:
//导出 excel public function excel(){ header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename=回访统计.xls'); header('Pragma: no-cache'); header('Expires: 0'); $title = array('序号','日期', '患者号码','姓名','性别','年龄','疾病类型'); $where=array(); $where['hospital_id']=intval($_GET['id']); $where['created']=array(array('egt',strtotime($_GET['start'].' 00:00:00')),array('elt',strtotime($_GET['end'].' 23:59:59'))); $data=M("visit","","DB_CONFIG2")->field('created,tel,name,sex,age,entity')->where($where)->order('created desc')->select(); echo implode("\t", $title), "\n"; foreach($data as $k=>$v){ array_unshift($data[$k],$k+1); $data[$k]['created']=date('Y-m-d',$v['created']); if($v['sex'] == 1){ $data[$k]['sex']='男'; }else if($v['sex'] == 2){ $data[$k]['sex']='女'; }else{ $data[$k]['sex']=' '; } } foreach ($data as$value) { echo ' '.implode("\t", $value), "\n"; } }