//导出XLS文件
public function
dataToXls($filename,$fields,$data,$datasum=array()){
header("Content-Type: application/vnd.ms-excel;charset=gbk");
header("Content-Disposition: attachment; filename=".$filename.".xls");
header("Cache-Control:max-age=0");
foreach($fields as $v){
$v = iconv(‘utf-8‘,‘gbk‘,$v);
echo $v."\t";
}
print("\n");
$sep = "\t";
foreach($data as $value){
$schema_insert = ‘‘;
foreach($fields as $k => $v){
$value[$k] = iconv(‘utf-8‘,‘gbk‘,$value[$k]);
if(!isset($value[$k])){
$schema_insert .=
"NULL".$sep;
}elseif($value[$k] != ‘‘){
$schema_insert .= $value[$k].$sep;
}else{
$schema_insert .= "".$sep;
}
}
$schema_insert = str_replace($sep."$","",$schema_insert);
$schema_insert .= "\t";
print(trim($schema_insert));
print "\n";
}
foreach($fields as $k => $v){
$datasum[$k] =
iconv(‘utf-8‘,‘gbk‘,$datasum[$k]);
echo $datasum[$k].$sep;
}
exit;