首页 > 代码库 > Excel导出
Excel导出
转:
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导出
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。