因为专注,所以专业
2005 - 2020

一个简单的PHP导出Excel类

时间:2020-06-29 13:50:56    作者:八叔模板堂

一个简单的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";
	}
}
赞(0
免费拨打  111-1111-1111
免费拨打  111-1111-1111免费拨打 111-1111-1111
微信二维码
手机二维码
返回顶部
返回顶部返回顶部