其实php输出excel倒是很简单
第一:
<?php
header("Content-Type: application/vnd.ms-excel; charset=gb2312");
//解释下,这里为何用gb2312,因为默认windows的编码用的是中文编码,如果用utf-8会乱码的
//但是如果页面实在是用utf-8编码的怎么办呢?
//iconv(‘utf-8’, ‘gb2312’, ‘内容’);这样就转换过来了~~
header("Content-Disposition:filename=Joyous.xls");
?>
放在文档最上面,把文档里面其他内容全部删除了
第二:乱码最主要原因就是编码不统一~~~
下面是我的例子贴出代码(页面编码gb2312)
<?php
header("Content-Type: application/vnd.ms-excel; charset=gb2312");
header("Content-Disposition:filename=Joyous.xls");
?>
<table width="210" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="70">姓名</td>
<td width="70"><font>年龄</font></td>
<td width="70">班级</td>
</tr>
<tr>
<td>张三</td>
<td>24</td>
<td>06</td>
</tr>
<tr>
<td>李四</td>
<td>25</td>
<td>04</td>
</tr>
<tr>
<td>王五</td>
<td>25</td>
<td>02</td>
</tr>
</table>
附注:这样可以把table的内容替换成你从数据库读取出来的~~~^^