Excel导出

Posted 316137590

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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导出的主要内容,如果未能解决你的问题,请参考以下文章

hutool工具导出excel代码示例

hutool工具导出excel代码示例

jsp导入和导出excel的代码(jsp连接excel的方法)

java五行代码导出Excel

急求php导出生成excel的代码

如何用java导入Excel数据到数据库?