2015年3月12日星期四

PHP 保存 Excl文件.

先上代码.
要注意他的头部定义方式.必须要这样设置。当调用的时候就会直接下载成excl格式的了

<?php    
session_start();   
 $date = mktime();   
 $date = date("Y-m-d",$date);   
 $filename = "$date.xls";   
 header("Content-type: application/vnd.ms-excel");   
 header("Content-Disposition: attachment; filename=$filename");  
 header("Expires: 0");    
 header("Cache-Control: must-revalidate, post-check=0,pre-check=0"); 
 header("Pragma: public");?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
</head>

<body>
<table border=1 width=100%>
    <tr>
        <td>아이디</td>
        <td>등급</td>
    </tr>
    <?php    for($i=1; $i<=5; $i++){        echo        "         <tr>         <td>$i</td>         <td>sm.$i</td>         </tr>         ";    }    ?>
</table>
</body>
</html>

1 条评论: