最简单的导出EXCEL

	public function put_csv($list,$title){
		$file_name="CSV".date("mdHis",time()).".csv";
		header ( 'Content-Type: application/vnd.ms-excel' );
		header ( 'Content-Disposition: attachment;filename='.$file_name );
		header ( 'Cache-Control: max-age=0' );
		$file = fopen('php://output',"a");
		$limit=1000;
		$calc=0;
		foreach ($title as $v){
			$tit[]=iconv('UTF-8', 'GB2312//IGNORE',$v);
		}
		fputcsv($file,$tit);
		foreach ($list as $v){
			$calc++;
			if($limit==$calc){
				ob_flush();
				flush();
				$calc=0;
			}
			foreach ($v as $t){
				$tarr[]=iconv('UTF-8', 'GB2312//IGNORE',$t);
			}
			fputcsv($file,$tarr);
			unset($tarr);
		}
		unset($list);
		fclose($file);
		exit();
	}
	
	
		
	public function excel(){
		$wherestr=" id > 1000";
		$list1 = M('user')->where($wherestr)->field("*")->order('id desc')->limit(0,1000)->select();
		$list=null;
		foreach($list1 as $vo){
			$dd["id"]=$vo["id"];     
			$dd["nickname"]=$vo["nickname"];  
			$dd["signid"]=$vo["signid"];  
			$dd["snumber"]=$vo["snumber"];  
			$dd["inno"]=$vo["inno"];  
			$dd["chinesezodiac"]=$vo["chinesezodiac"];  
			$dd["mobile"]=$vo["mobile"];  
			$dd["firstname"]=$vo["firstname"];  
			$dd["lastname"]=$vo["lastname"];  
			$dd["cname"]=$vo["cname"];  
			$dd["email"]=$vo["email"];  
			if($vo['matchtp']==1){
				$dd["matchtp"]="Random"; 
			}else{
				$dd["matchtp"]="Intentional"; 
			}
			$dd["matchid"]=$vo["matchid"]; 
			
			if(!empty($vo["matchid"])) {
				$dd["matchid_name"]=getoneid($vo["matchid"],"cname","user"); 
			}else{
				$dd["matchid_name"]=""; 
			}
			if(getcount(" userid=".$vo["id"]." or userid2=".$vo["id"]." ","id","checkinsign")>0){
				$dd["matchid_status"]='匹配成功'; 
			}else{
				$dd["matchid_status"]='匹配失败'; 
			}

			$dd["gender"]=$vo["gender"];  
			if($vo['vip']==1){
				$dd["vip"]="是"; 
			}else{
				$dd["vip"]="否"; 
			}
			switch(intval($vo["stay"])){
				case 1:
					$dd["stay"]="上海"; 
					break;
				case 2:	
					$dd["stay"]="厦门"; 
					break;
				case 3:	
					$dd["stay"]="上海 & 厦门"; 
					break;    
				default:		
					$dd["stay"]="未选择";  
					break;		
			}
			$dd["game1"]=$vo["game1"];  
			$dd["game2"]=$vo["game2"];  
			$dd["game3"]=$vo["game3"];  
			$dd["passport"]="'".$vo['passport'];
			$dd["groupid"]="'".$vo['groupid'];
			$list[]=$dd;				
		}				
		$csv_title=array('编号','nickname','signid','No.','chinesezodiac','生肖','mobile','firstname','lastname','中文名','email','匹配','匹配id','用户中文名','匹配结果','性别','是否vip','住宿','game1','game2','game3','passport','分组');
    	$this->put_csv($list,$csv_title);
	}

  

上一篇:7、NC单据左侧实现查询数据加载至新界面


下一篇:VO、DTO、DO、PO是什么?