1 导出excel表格功能
/**
* excel 导出
*
* @param string $filename 文件名
* @param array $title 标题(一维数组)
* @param array $list 列表(二维数组)
*/
function excel_out($filename,$titles,$list)
{
$file_type = "vnd.ms-excel";
$file_ending = "xls";
header("Content-Type: application/$file_type;charset=utf-8");
header("Content-Disposition: attachment; filename=$filename.$file_ending");
header("Pragma: no-cache");
header("Expires: 0");
$len = count($titles);
for($i=0; $i<$len; $i++)
{
echo iconv('utf-8','gbk//IGNORE',$titles[$i])."\t";
if($i+1 == $len) echo "\n";
}
$len = count($list);
for($i=0; $i<$len; $i++)
{
if($i == 0) $keys = array_keys($list[0]);
for($k=0; $k<count($list[$i]); $k++)
{
echo iconv('utf-8','gbk//IGNORE',str_replace("\n"," ",$list[$i]["{$keys[$k]}"]))."\t";
if($k+1 == count($list[$i])) echo "\n";
}
}
}