html5中文学习网

您的位置: 首页 > 网络编程 > PHP编程 » 正文

php 导入导出excel:php导出excel_PHP教程_编程技术

[ ] 已经帮助:人解决问题

/**
* @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 "<META HTTP-EQUIV='Content-Type' CONTENT='text/html;charset=$type'>";
echo '<table border="1" cellspacing="1" cellpadding="1"><tr align="center">';
foreach ($array as $val) {
echo "<td width='100'>$val</td>";
}
echo '</tr>';
foreach ($data as $val) {
if(is_array($val)){
echo '<tr align="center">';
foreach ($val as $v) {
echo '<td width="120" height="30">' . $v . '</td>';
}
echo '</td>';
}else {
echo '<tr align="center">';
echo '<td width="120" height="30">' . $val . '</td>';
echo '</td>';
}
}
echo '</table>';
exit;
}
  本文链接http://www.cxybl.com/html/wlbc/Php/20130326/37395.html
nM3HTML5中文学习网 - HTML5先行者学习网
nM3HTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助