zoukankan      html  css  js  c++  java
  • php 生成 word 文档

     1 <?php 
     2 class word
     3 { 
     4     function start()
     5     {
     6         ob_start();
     7         echo '<html xmlns:o="urn:schemas-microsoft-com:office:office"
     8         xmlns:w="urn:schemas-microsoft-com:office:word"
     9         xmlns="http://www.w3.org/TR/REC-html40">';
    10     }
    11 
    12     function save($path)
    13     {
    14         echo "</html>";
    15         $data = ob_get_contents();
    16         ob_end_clean();
    17         $this->wirtefile ($path,$data);
    18     }
    19       
    20     function wirtefile ($fn,$data)
    21     {
    22         $fp=fopen($fn,"wb");
    23         fwrite($fp,$data);
    24         fclose($fp);
    25     }
    26 }
    27 
    28 $html = ' 
    29     <table width=600 cellpadding="6" cellspacing="1" bgcolor="#336699"> 
    30     <tr bgcolor="White"> 
    31      <td>baidu</td> 
    32      <td><img src="http://mpic.tiankong.com/ecc/3e3/ecc3e349338dbe58603cf270d9cd7c9c/640.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/watermark,image_cXVhbmppbmcucG5n,t_90,g_ne,x_5,y_5"></td>
    33      <td><a href="http://www.baidu.com" target="_blank" >http://www.baidu.com</a></td> 
    34     </tr> 
    35     <tr bgcolor="red"> 
    36      <td>baidu</td> 
    37      <td><a href="http://www.baidu.com" target="_blank" >http://www.baidu.com</a></td> 
    38     </tr> 
    39     <tr bgcolor="White"> 
    40      <td colspan=2 > 
    41      baidu<br> 
    42      </td> 
    43     </tr> 
    44     </table> 
    45 '; 
    46 
    47 //批量生成 
    48 for($i=1;$i<=1;$i++){ 
    49     $word = new word(); 
    50     $word->start(); 
    51     $wordname = 'TESTDOC-'.$i.".doc"; 
    52     echo $html; 
    53     $word->save($wordname); 
    54     ob_flush();//每次执行前刷新缓存 
    55     flush(); 
    56 }
    57 
    58 
    59 
    60 
    61 
    62 
    63 
    64  
    既不回头,何必不忘; 既然无缘,何须誓言; 今日种种,逝水无痕; 明夕何夕,君已陌路;
  • 相关阅读:
    2019 icpc西安邀请赛 点分治
    2019ccpc 秦皇岛
    hdu 5354 树上点分治
    cf 632E FFT+快速幂
    hdu 4812 树分治+逆元+手写hashmap
    2019 上海网络赛G 手写哈希map+字符串hash
    2019 上海icpc网络赛 C FFT优化卷积+小范围暴力
    hdu 6198 杜教BM
    洛谷P3804 后缀自动机
    集合总结
  • 原文地址:https://www.cnblogs.com/zyjfire/p/7280033.html
Copyright © 2011-2022 走看看