
/** |
* 输出XLS的头信息 |
* 注:使用此函数前后都不应有任何数据输出 |
* @param $data Array 下载的数据 |
* @param $file_name String 下载的文件名 |
*/ |
|
function outputXlsHeader($data,$file_name = 'export') |
{ |
header('Content-Type: text/xls'); |
header ( "Content-type:application/vnd.ms-excel;charset=utf-8" ); |
$str = mb_convert_encoding($file_name, 'gbk', 'utf-8'); |
header('Content-Disposition: attachment;filename="' .$str . '.xls"'); |
header('Cache-Control:must-revalidate,post-check=0,pre-check=0'); |
header('Expires:0'); |
header('Pragma:public'); |
|
$table_data = '<table border="1">'; |
|
foreach ($data as $line) |
{ |
$table_data .= '<tr>'; |
foreach ($line as $key => &$item) |
{ |
$item = mb_convert_encoding($item, 'gbk', 'utf-8'); |
$table_data .= '<td>' . $item . '</td>'; |
} |
$table_data .= '</tr>'; |
} |
$table_data .='</table>'; |
echo $table_data; |
die(); |
} |



