一个PHP导出XLS的类
//导出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;
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。