PHP 直接使用html輸出excel


 1 <?php
 2 header("Cache-Control:public");
 3 header("Pragma:public");
 4 
 5 header( "Content-Type: application/vnd.ms-excel; name='excel'" );//表示輸出的類型為excel文件類型
 6 
 7 header( "Content-type: application/octet-stream" );//表示二進制數據流,常用於文件下載
 8 
 9 header( "Content-Disposition: attachment; filename=".date('Y-m-d',time())."CCHRC調查問卷.xls");//彈框下載文件
10 
11 //以下三行代碼使瀏覽器每次打開這個頁面的時候不會使用緩存從而下載上一個文件
12 header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
13 header( "Pragma: no-cache" );
14 header( "Expires: 0" );
15 ?>
16 <html xmlns:o="urn:schemas-microsoft-com:office:office"
17       xmlns:x="urn:schemas-microsoft-com:office:excel"
18       xmlns="http://www.w3.org/TR/REC-html40">
19 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
20 <head>
21     <meta http-equiv="Content-type" content="text/html;charset=utf-8" />
22 </head>
23 
24 <body style="font-family: 'Microsoft YaHei UI'">
25 <table border="1">
26     <tr><th colspan="<?=$colspan?>" style="text-align: center;font-size: 20pt">調查問卷</th></tr>
27     <tr>
28     <td>username</td><td>time</td>
29         <?php foreach($questions as $ques): ?>
30             <td style="font-size: 12pt;"><?= $ques ?></td>
31         <?php endforeach; ?>
32     </tr>
33     <?=$tr?>
34 </table>
35 </body>
36 <html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM