/**
* @param string $filname //输出的文件名
* @param string $type //编码类型
* @param string $array //excel的标题
* @param string $data //需要的数据data
**/
function exportExcel($filname, $type = 'utf-8', $array, $data) {
if (empty ($data)) {
echo "<script>alert('sorry,no data!');history.go(-1);</script>";
exit;
}
$filname = iconv("utf-8", "gb2312", $filname);
header("Content-type:application/vnd.ms-excel;");
header("Content-Disposition:attachment;filename=$filname.xls");
echo "
";
echo '
';
foreach ($array as $val) {
echo "$val | ";
}
echo '
';
foreach ($data as $val) {
if(is_array($val)){
echo '';
foreach ($val as $v) {
echo '' . $v . ' | ';
}
echo '';
}else {
echo '
';
echo '' . $val . ' | ';
echo '';
}
}
echo '
';
exit;
}
本文链接http://www.cxybl.com/html/wlbc/Php/20130326/37395.html
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn