首页 > Web开发 > 详细

一个PHP导出XLS的类

时间:2014-05-26 21:38:24      阅读:332      评论:0      收藏:0      [点我收藏+]

//导出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的类

原文:http://www.cnblogs.com/caiwp35/p/3745919.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!