<p>/** </p><p>* 导出数据为excel表格 </p><p>*@param $data 一个二维数组,结构如同从数据库查出来的数组 </p><p>*@param $title excel的第一行标题,一个数组,如果为空则没有标题 </p><p>*@param $filename 下载的文件名 </p><p>*@examlpe $arr[] = array('12','13','14','15'); exportexcel($arr,array('id','账户','密码','昵称'),'文件名!');</p><p>*/ </p><p>function exportexcel($data=array(),$title=array(),$filename='report'){</p><p> header("Content-type:application/octet-stream");</p><p> header("Accept-Ranges:bytes");</p><p> header("Content-type:application/vnd.ms-excel");</p><p> header("Content-Disposition:attachment;filename=".$filename.".xls");</p><p> header("Pragma: no-cache");</p><p> header("Expires: 0"); //导出xls 开始</p><p> if (!empty($title)){</p><p> foreach ($title as $k => $v) {</p><p> $title[$k]=iconv("UTF-8", "GB2312",$v);</p><p> }</p><p> $title= implode("\t", $title);</p><p> echo "$title\n";</p><p> }</p><p> if (!empty($data)){</p><p> foreach($data as $key=>$val){</p><p> foreach ($val as $ck => $cv) {</p><p> $data[$key][$ck]=iconv("UTF-8", "GB2312", $cv);</p><p> }</p><p> $data[$key]=implode("\t", $data[$key]);</p><p> }</p><p> echo implode("\n",$data);</p><p> } </p><p>}</p>