php 不使用COM 显示MYSQL导出下载(表格资料保存成XLS)

来源:互联网 发布:阿里云域名免备案 编辑:程序博客网 时间:2024/06/13 04:32
 
//实例代码 doexport.php(导出页)
if($_GET["select"]=="ip"){$f_namex="所有的上网IP资料";echo $f_namex;print"</tr></span></th><tr><td>IP地址</td><td> 状态</td><td>IP使用者</td><td> 使用IP设备</td><td>IP管理者</td><td>最后更改时间</td><th >部门</td><th>公司</td><td>备注</td></tr>";header("Content-type: text/html; charset=utf-8");header("Content-type:application/vnd.ms-excel;charset=UTF-8"); header("Content-Disposition: attachment; filename=".$f_namex.".xls");//文件名称include("./inc/consol.php");include("./inc/dbconnect.php");$com = new common();$opt = new oprate();$sql="SELECT * FROM Fcomputer.ip";$result=mysql_query($sql,$conn);while($row=mysql_fetch_row($result)){print("<tr><td ><span class='style12'>". $row[0]."</span></td>");print("<td >".$row[1]."</td>");print("<td >".$row[2]."</td>");print("<td >". $row[3]."</td>");print("<td >". $row[4]."</td>");print("<td >". $row[5]."</td>");print("<td >". $row[6]."</td>");print("<td >". $row[7]."</td>");print("<td >". $row[8]."</td>");print("<td >". $row[9]."</td></tr>");} print "</table>";}


调用导出下载

<?php if($_POST['sum_exToxls']!=NULL){if($_POST['select_item']){//document.open("text/html",'""),$my_company=$_POST['company'];$my_seelct=$_POST['select_item'];header('location: doexport.php?company='.$my_company.'&select='.$my_seelct);}}?>

注意:导出调用时如果使用,window.open 打开doexport.php(导出页)

header("Content-type:application/vnd.ms-excel;charset=UTF-8"); 不会任务错误,也不会得到想要的效果