Заголовок экспорт Excel только PHP

1 /**
 2  * Export data to excel
 3  *@param $data    A two-dimensional array, the structure of which is similar to the array found from the database
 4  *@param $title   excel The first row title of, an array, if empty, no title
 5  *@param $filename Downloaded file name
 6  *@examlpe10  */
11 function exportexcel($data=array(),$title=array(),$filename='report'){
12     ob_end_clean(); 
13     ob_start(); 
14     header("Content-type:application/octet-stream");
15     header("Accept-Ranges:bytes");
16     header("Content-type:application/vnd.ms-excel");
17     header("Content-Disposition:attachment;filename=".$filename.".xls");
18     header("Pragma: no-cache");
19     header("Expires: 0");
20     //export xls start
21     if (!empty($title)){
22         foreach ($title as $k => $v) {
23             $title[$k]=iconv("UTF-8", "GB2312",$v);
24         }
25         $title= implode("\t", $title);
26         echo "$title\n";
27     }
28     if (!empty($data)){
29         foreach($data as $key=>$val){
30             foreach ($val as $ck => $cv) {
31                 $data[$key][$ck]=iconv("UTF-8", "GB2312", $cv);
32             }
33             $data[$key]=implode("\t", $data[$key]);
34         }
35         echo implode("\n",$data);
36     }
37 }
Old-fashioned Oystercatcher