Chinaunix首页 | 论坛 | 博客
  • 博客访问: 449651
  • 博文数量: 141
  • 博客积分: 211
  • 博客等级: 入伍新兵
  • 技术积分: 1049
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-17 16:25
个人简介

如此经年,望尽千帆。

文章分类

全部博文(141)

文章存档

2014年(73)

2013年(65)

2012年(3)

我的朋友

分类: PHP

2013-12-15 08:16:29

转自:

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="">';
  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 .='
  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. iGo运
    单号
    ].' />
    '
    .$val['box_code'].'
    日期 '.date('Y-m-d',$val[create_date]).' 标示
    姓名
    '.$val[code].'/'.$val['orderid'].'
    '
    .$val['orderinfo']['user_name'].'
    件数 3 重量 56.5 品名 咬咬了,吸盘碗,学饮杯,鱼干油
    服务
    类别
    库房服务 服务
    要求
    合小箱


    客户
    备注

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



    到货
    情况



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












  76. ';
  77.  }
  78.      $word->start();
  79.      $filename = '拣货单导出.doc';
  80.      echo $html;
  81.       $word->save($filename);


  82.       //文件的类型
  83.       header('Content-type: application/word');
  84.       header('Content-Disposition: attachment; filename="拣货单导出.doc"');
  85.       readfile($filename);
  86.       ob_flush();
  87.       flush();
  88.      exit();
  89. //导出word --end--
阅读(726) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~