多得不说,直接上代码:
/**
* @date 2018-10-8
* demo:
* $data=[
* [0]=>[
* 'phone'=>'123456',
* 'company'=>'ABC'
* ],
* [1]=>[
* 'phone'=>'123456',
* 'company'=>'ABC'
* ]
* ]
* $header='电话,公司代码';
* $this->OutExcel($data,$header)
*/
public function OutExcel(array $data,$header='',$title='表格'){
if(!strlen($header)) return false;
header("Content-type:application/vnd.ms-excel;charset=utf-8");
header("Content-Disposition:filename=".urlencode($title).".xls");
$str=str_replace([',',','],["\t","\t"],$header)."\r";
foreach($data as $vol){
if(is_array($vol)){
foreach($vol as $v){
$str.=$v.(next($vol)?"\t":"\r");
}
}
}
$str=iconv('UTF-8',"GB2312//IGNORE",$str);
exit($str);
}