一个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;

一个PHP导出XLS的类,布布扣,bubuko.com

一个PHP导出XLS的类

上一篇:JQuery中$.ajax()方法参数


下一篇:使用supervisor提高nodejs调试效率