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  
    既不回头,何必不忘; 既然无缘,何须誓言; 今日种种,逝水无痕; 明夕何夕,君已陌路;
  • 相关阅读:
    ServU和win2003防火墙的设置
    面试题02.05 链表求和
    【每日一题】LeetCode1. 两数之和
    【每日一题】Leetcode50. Pow(x,n)
    ASP连接查询access和sqlserver的代码
    各种播放器(视频点播)代码大全 
    电脑操作最忌讳的小动作
    网络小知识
    C#、Java比较
    10年互联网十大失败案例
  • 原文地址:https://www.cnblogs.com/zyjfire/p/7280033.html
Copyright © 2011-2022 走看看