public function toExcel(){ $map =array(); $ids = input('ids'); if($ids&& !empty($ids)){ $map['id']=array('in',$ids); } $data = Db::name('cms_apply')->where($map)->select(); foreach($data as $k=>$v){ $data[$k]['create_time']=date("Y-m-d H:i:s",$v['create_time']); } $title = array("序號","姓名","性別","民族","生日","備註","報名時間"); exportexcel($data,$title,"報名信息表".date("Y-m-d H:i:s")); }
function exportexcel($data=array(),$title=array(),$filename='report'){ header("Content-type:application/octet-stream"); header("Accept-Ranges:bytes"); header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:attachment;filename=".$filename.".xls"); header("Pragma: no-cache"); header("Expires: 0"); //導出xls 開始 if (!empty($title)){ foreach ($title as $k => $v) { $title[$k]=iconv("UTF-8", "GB2312",$v); } $title= implode("\t", $title); echo "$title\n"; } if (!empty($data)){ foreach($data as $key=>$val){ foreach ($val as $ck => $cv) { $data[$key][$ck]=iconv("UTF-8", "GB2312", $cv); } $data[$key]=implode("\t", $data[$key]); } echo implode("\n",$data); } exit; }