Home > Backend Development > PHP Tutorial > php导出word格式数据的范例代码

php导出word格式数据的范例代码

WBOY
Release: 2016-06-13 11:42:51
Original
1262 people have browsed it

php导出word格式数据的实例代码

转自:http://www.jbxue.com/article/13631.html

php导出word格式数据的代码实例,有需要的朋友可以参考一下。
本节内容:
一个php导出word文档的类
例子:

点击(此处)折叠或打开

  1. ?php
  2. /**
  3. *?生成word文档的类
  4. *?by www.jbxue.com
  5. */
  6. class?word
  7. {?
  8. ????function start()
  9. ????{
  10. ????????ob_start();
  11. ????????echo?'
  12. ????????xmlns:w="urn:schemas-microsoft-com:office:word"
  13. ????????xmlns="http://www.w3.org/TR/REC-html40">';
  14. ????????}
  15. ????function save($path)
  16. ????{?
  17. ????????echo?"";
  18. ????????$data?=?ob_get_contents();
  19. ????????ob_end_clean();
  20. ????????$this->wirtefile?($path,$data);
  21. ????}
  22. ????function wirtefile?($fn,$data)
  23. ????{
  24. ????????$fp=fopen($fn,"wb");
  25. ????????fwrite($fp,$data);
  26. ????????fclose($fp);
  27. ????}
  28. }
  29. //导出的程序文件
  30. //导出?---start---
  31. require SITE_ROOT.'include/word.class.php';?//类文件放在根目录下的include文件夹下
  32. $word?=?new?word();
  33. //查询数据填入word 中
  34. $result?=?$db->query("SELECT * FROM ".DB_PRE."box where status='9' order by boxid DESC");
  35. while($r?=?$db->fetch_array($result))
  36. {
  37. ??$r['orderinfo']?=?$db->get_one("SELECT * FROM ".DB_PRE."order where orderid='".$r['orderid']."'");
  38. ??$r['wrapinfo']?=?$db->get_one("SELECT * FROM ".DB_PRE."wrap where orderid='".$r['orderid']."'");
  39. ?$boxlist[]?=?$r;
  40. }
  41. ?foreach($boxlist as $key=>$val){?
  42. ????$order->UPCAbarcode($val['box_code']);
  43. ????$html?.=' www.jbxue.com
  44. ????
  45. ?
  46. ??????
  47. ?
  48. ??????
  49. ?
  50. ??????
  51. ?
  52. ??????
  53. ?
  54. ??????
  55. ?
  56. ??????
  57. ?
  58. ????
  59. ?
  60. ????
  61. ?
  62. ??????
  63. ?
  64. ??????
  65. ?
  66. ??????
  67. ?
  68. ??????
  69. ?
  70. ??????
  71. ?
  72. ??????
  73. ?
  74. ????
  75. ?
  76. ????
  77. ?
  78. ??????
  79. ?
  80. ??????
  81. ?
  82. ??????
  83. ?
  84. ??????
  85. ?
  86. ????
  87. ?
  88. ????
  89. ?
  90. ??????
  91. ?
  92. ??????
  93. ?
  94. ????
  95. ?
  96. ????
  97. ?
  98. ??????
  99. ?
  100. ??????
  101. ?
  102. ????
  103. ?
  104. ????
  105. iGo运
    单号
    php导出word格式数据的范例代码].' />
    '
    .$val['box_code'].'
    日期 '.date('Y-m-d',$val[create_date]).' 标示
    姓名
    '.$val[code].'/'.$val['orderid'].'
    '
    .$val['orderinfo']['user_name'].'
    件数 3 重量 56.5 品名 咬咬了,吸盘碗,学饮杯,鱼干油
    服务
    类别
    库房服务 服务
    要求
    合小箱


    客户
    备注

    '.$val['orderinfo']['beizhu'].'



    到货
    情况



    什么问题?果点不到
    什么问题?果点不到
    什么问题?果点不到











  106. ';?
  107. ?}
  108. ?????$word->start();
  109. ?????$filename?=?'拣货单导出.doc';
  110. ?????echo?$html;
  111. ??????$word->save($filename);
  112. ??????//文件的类型
  113. ??????header('Content-type: application/word');
  114. ??????header('Content-Disposition: attachment; filename="拣货单导出.doc"');
  115. ??????readfile($filename);
  116. ??????ob_flush();
  117. ??????flush();
  118. ?????exit();
  119. //导出word?--end--
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template