当前位置: 代码迷 >> PHP >> php导出word格式数据的范例代码
  详细解决方案

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

热度:573   发布时间:2013-12-17 12:06:34.0
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?'<html xmlns:o="urn:schemas-microsoft-com:office:office"
  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?"</html>";
  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?.='<table width=800 cellpadding="6" align="center" cellspacing="5" bgcolor="#000000"> www.jbxue.com
  44. ????<tr bgcolor="White" height="50">?
  45. ??????<td width=80 style="border:1px solid #c8c8c8;">iGo运<br/>单号</td>?
  46. ??????<td width=300 style="border:1px solid #c8c8c8;"><img src='.$val['iGocode_code'].' /><br/> '.$val['box_code'].'</td>?
  47. ??????<td width=60 style="border:1px solid #c8c8c8;">日期</td>?
  48. ??????<td width=100 style="border:1px solid #c8c8c8;">'.date('Y-m-d',$val[create_date]).'</td>?
  49. ??????<td width=100 style="border:1px solid #c8c8c8;">标示<br/>姓名</td>?
  50. ??????<td width=240 style="border:1px solid #c8c8c8;">'.$val[code].'/'.$val['orderid'].'<br/>'.$val['orderinfo']['user_name'].'</td>?
  51. ????</tr>?
  52. ????<tr bgcolor="White">?
  53. ??????<td width=60 style="border:1px solid #c8c8c8;">件数</td>?
  54. ??????<td width=40 style="border:1px solid #c8c8c8;">3</td>?
  55. ??????<td width=40 style="border:1px solid #c8c8c8;">重量</td>?
  56. ??????<td width=150 style="border:1px solid #c8c8c8;">56.5</td>?
  57. ??????<td width=40 style="border:1px solid #c8c8c8;">品名</td>?
  58. ??????<td width=390 style="border:1px solid #c8c8c8;">咬咬了,吸盘碗,学饮杯,鱼干油</td>?
  59. ????</tr>?
  60. ????<tr bgcolor="White">?
  61. ??????<td width=110 style="border:1px solid #c8c8c8;">服务<br/>类别</td>?
  62. ??????<td width=200 style="border:1px solid #c8c8c8;">库房服务</td>?
  63. ??????<td width=110 style="border:1px solid #c8c8c8;">服务<br/>要求</td>?
  64. ??????<td width=280 style="border:1px solid #c8c8c8;">合小箱</td>?
  65. ????</tr>?
  66. ????<tr bgcolor="White">?
  67. ??????<td width=120 style="border:1px solid #c8c8c8;"><br/><br/>客户<br/>备注<br/><br/></td>?
  68. ??????<td width=580 style="border:1px solid #c8c8c8;">'.$val['orderinfo']['beizhu'].'</td>?
  69. ????</tr>?
  70. ????<tr bgcolor="White">?
  71. ??????<td width=120 style="border:1px solid #c8c8c8;"><br/><br/><br/>到货<br/>情况<br/><br/><br/><br/></td>?
  72. ??????<td width=580 style="border:1px solid #c8c8c8;">什么问题?果点不到<br/>什么问题?果点不到<br/>什么问题?果点不到<br/><br/><br/><br/><br/><br/><br/><br/></td>?
  73. ????</tr>?
  74. ????</table> <br/><br/><br/><br/>
  75. ';?
  76. ?}
  77. ?????$word->start();
  78. ?????$filename?=?'拣货单导出.doc';
  79. ?????echo?$html;
  80. ??????$word->save($filename);
  81. ??????//文件的类型
  82. ??????header('Content-type: application/word');
  83. ??????header('Content-Disposition: attachment; filename="拣货单导出.doc"');
  84. ??????readfile($filename);
  85. ??????ob_flush();
  86. ??????flush();
  87. ?????exit();
  88. //导出word?--end--
  相关解决方案