>  기사  >  백엔드 개발  >  php导出word格式数据的代码实例_php实例

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

WBOY
WBOY원래의
2016-05-17 08:52:44883검색

本节内容:
一个php导出文档的类

例子:

复制代码 代码如下:

/**
* 生成word文档的类
*
*/
class word
{
    function start()
    {
        ob_start();
        echo '        xmlns:w="urn:schemas-microsoft-com:office:word"
        xmlns="http://www.w3.org/TR/REC-html40">';
        }
    function save($path)
    {    
        echo "";
        $data = ob_get_contents();
        ob_end_clean();

        $this->wirtefile ($path,$data);
    }

    function wirtefile ($fn,$data)
    {
        $fp=fopen($fn,"wb");
        fwrite($fp,$data);
        fclose($fp);
    }
}

//导出的程序文件
//导出 ---start---
require SITE_ROOT.'include/word.class.php';  //类文件放在根目录下的include文件夹下
$word = new word();
//查询数据填入word 中
$result = $db->query("SELECT * FROM ".DB_PRE."box where status='9' order by boxid DESC");
while($r = $db->fetch_array($result))
{
  $r['orderinfo'] = $db->get_one("SELECT * FROM ".DB_PRE."order where orderid='".$r['orderid']."'");
  $r['wrapinfo']  = $db->get_one("SELECT * FROM ".DB_PRE."wrap where orderid='".$r['orderid']."'");
 $boxlist[] = $r;
}

 foreach($boxlist as $key=>$val){
    $order->UPCAbarcode($val['box_code']);

    $html .='


   
     
     
     
     
     
     
   
   
     
     
     
     
     
     
   
   
     
     
     
     
   
   
     
          
   
   
     
     
   
   
iGo运
单号
php导出word格式数据的代码实例_php实例
  '.$val['box_code'].'
日期 '.date('Y-m-d',$val[create_date]).' 标示
姓名
'.$val[code].'/'.$val['orderid'].'
'.$val['orderinfo']['user_name'].'
件数 3 重量 56.5 品名 咬咬了,吸盘碗,学饮杯,鱼干油
服务
类别
库房服务 服务
要求
合小箱


客户
备注

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



到货
情况



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












'; 
 }
     $word->start();
     $filename = '拣货单导出.doc';
     echo $html;
      $word->save($filename);

      //文件的类型
      header('Content-type: application/word');
      header('Content-Disposition: attachment; filename="拣货单导出.doc"');
      readfile($filename);
      ob_flush();
      flush();
     exit();
//导出word --end--
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.