检索出的内容显示出来以后,按导出键导出Excel格式?应该怎么编写程序,下面是我检索的那段程序。<?php
$uname=$_SESSION["loginname"];
$ulevel=$_SESSION['level'];
$conn=mysql_connect("localhost","root","root") or die("数据库服务器连接错误".mysql_error());
mysql_select_db("yiyuan",$conn) or die("数据库访问错误".mysql_error());
mysql_query("set names gb2312");
$sql="select unit from usertable where name='$uname';";
$result=mysql_query($sql,$conn);
$row=mysql_fetch_row($result);
mysql_free_result($result);
$unit=$row[0];//得到登录用户单位
$date1=$_POST[date1];
$date2=$_POST[date2];
$res = mysql_query("select * from tousu where date <= '$date2' and  date>='$date1' order by date asc  ");
$row = mysql_fetch_array($res);
if($row==false)
{
echo "<div align='center' style='color:#FF0000; font-size:12px'>对不起,您检索的投诉信息不存在!</div>";
}
do{

 ?>                  <tr bgcolor="#FFFFFF">
<td ><?php echo $row[1]; ?></td>
                  <td ><?php echo $row[2]; ?></td>
                  <td ><?php echo $row[5]; ?></td>
                  <td ><?php echo $row[6]; ?></td>
                  <td ><?php echo $row[7]; ?></td>
                  <td ><?php echo $row[8]; ?></td>  
  
                  </tr>
<?php
}while($row=mysql_fetch_row($res));

?>
                  


</table>
<br />
<br />
<div id="form">
<form method="POST" action="5-2.php" border="5">
<INPUT TYPE="SUBMIT" VALUE="导 出">
</form>
</body>
</html>

解决方案 »

  1.   

    输出的格式还要调整一下~而且缺少header()告诉服务器你要生成的是excel文件
    就像这样
    header("Content-type:application/vnd.ms-excel");
    header("Content-Disposition:filename=".$filename.".xls");
    网上的样例有不少的~你可以看一下
      

  2.   

    phpexcel可以很好的做出相应的效果来
      

  3.   

    http://2611845.blog.163.com/blog/static/42371754200911241019564/?fromdm&fromSearch&isFromSearchEngine=yes下载个phpexecl 按上面来做,很好弄。
      

  4.   

    用phpExcel吧!去网上下载一个,百度一搜,里面有很多例子,直接套例子就行了