php 导出到Excel就是这么简单
查询出数据库信息后,需要导出到Excel表,片段如下:
header("Content-type:application/octet-stream");
header("Accept-Ranges:bytes");
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=www.lizu2010.com_".date("Y-m-d").".xls");
header("Pragma: no-cache");
header("Expires: 0");
//导出xls
开始
$tag1 = iconv("UTF-8",
"GB2312",‘No.‘);
$tag2 =
iconv("UTF-8", "GB2312",‘网址‘);
$tag3 = iconv("UTF-8", "GB2312",‘统计结果‘);
$tag4 = iconv("UTF-8",
"GB2312",‘关键字‘);
echo
"$tag1\t$tag2\t$tag3\t$tag4\n";
//$key_name = array_keys($arr);
$i = 1;
foreach($arr as
$val){
$No =
$i;
$url =
$val[‘url‘];
$rs =
$val[‘val‘];
$keyword = iconv("UTF-8",
"GB2312",$val[‘keyword‘]);
echo
"$No\t$url\t$rs\t$keyword\n";;
$i++;
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。