Code example for php to export word format data_PHP tutorial

WBOY
Release: 2016-07-13 10:25:09
Original
935 people have browsed it

Contents of this section:
A class for exporting documents in php

Example:

Copy code The code is as follows:

/**
* Class for generating word documents
*
*/
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)
{ >       ob_end_clean(); >          $fp=fopen($fn,"wb"); /Exported program files
//Export---start---
require SITE_ROOT.'include/word.class.php'; //Class files are placed in the include folder in the root directory
$word = new word();
//Fill the query data into 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运
单号

  '.$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--

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825204.htmlTechArticleContents in this section: A class example of php exporting documents: Copy the code as follows: ?php /*** Class for generating word documents **/ class word { function start() { ob_start(); echo 'html xmlns...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!