给大家分享一个导出 很好用 [ 新手入门 ]
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"=>"zhangsan"),
1=>array("uid"=>"132","name"=>"zhangsanddd"),
);
$key_name=array(
"uid"=>"用户ID",
"name"=>"姓名",
);
down_xls($user_info,$key_name,"用户信息表");
直接调用这个方法就可以了
共 9 条回复
dapeng
注册时间:2012-08-12
最后登录:2014-07-26
在线时长:0小时20分
最后登录:2014-07-26
在线时长:0小时20分
- 粉丝2
- 金钱1160
- 威望0
- 积分1160