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>

 

posted @ 2019-07-09 15:07  fpc  阅读(2747)  评论(0编辑  收藏  举报