码迷,mamicode.com
首页 > 其他好文 > 详细

Excel导出

时间:2017-02-25 11:59:21      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:ade   names   信息   tab   inf   info   back   filename   urlencode   

转:

http://www.yiichina.com/topic/4509

 

function down_xls($data, $keynames, $name=‘dataxls‘) {
$xls[] = "<html><meta http-equiv=content-type content=\"text/html; charset=UTF-8\"><body><table border=‘1‘>";
$xls[] = "<tr><td>ID</td><td>" . implode("</td><td>", array_values($keynames)) . ‘</td></tr>‘;
$index = 0;
if (preg_match(‘/MSIE/‘,$_SERVER[‘HTTP_USER_AGENT‘])) {
$name = rawurlencode($name);
}
foreach($data As $o) {
$line = array(++$index);
foreach($keynames AS $k=>$v) {
$line[] = htmlspecialchars($o[$k]);
}
$xls[] = ‘<tr><td>‘. implode("</td><td>", $line) . ‘</td></tr>‘;
}
$xls[] = ‘</table></body></html>‘;
$xls = join("\r\n", $xls);
header("Content-Type: application/vnd.ms-excel");
header(‘Content-Disposition: attachment; filename="‘.$name.‘.xls"‘);
die(mb_convert_encoding($xls,‘UTF-8‘,‘UTF-8‘));
}
$user_info=array(
0=>array("uid"=>"12","name"=>"fanguohui","sex"=>"nan"),
1=>array("uid"=>"132","name"=>"yuandahhui","sex"=>"nan"),
);
$key_name=array(
"uid"=>"id",
"name"=>"姓名",
"sex"=>"xingbie",
);
down_xls($user_info,$key_name,"用户信息表");

 

Excel导出

标签:ade   names   信息   tab   inf   info   back   filename   urlencode   

原文地址:http://www.cnblogs.com/myyuanyuan/p/6441375.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!