php exports a code instance of data in word format

  • 2020-11-25 07:11:44
  • OfStack

Contents of this section:
1 class for php to export documents

Example:


<?php
/**
*  generate word The document class 
* 
*/
class word
{ 
    function start()
    {
        ob_start();
        echo '<html xmlns:o="urn:schemas-microsoft-com:office:office"
        xmlns:w="urn:schemas-microsoft-com:office:word"
        xmlns="http://www.w3.org/TR/REC-html40">';
        }
    function save($path)
    {     
        echo "</html>";
        $data = ob_get_contents();
        ob_end_clean();

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

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

// The exported program file 
// export  ---start---
require SITE_ROOT.'include/word.class.php';  // Class files are placed in the root directory include folder 
$word = new word();
// Query data fill in word  In the 
$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 .='<table width=800 cellpadding="6" align="center" cellspacing="5" bgcolor="#000000">
    <tr bgcolor="White" height="50"> 
      <td width=80 style="border:1px solid #c8c8c8;">iGo shipment <br/> Order no. </td> 
      <td width=300 style="border:1px solid #c8c8c8;"><img src='.$val['iGocode_code'].' /><br/>&nbsp;&nbsp;'.$val['box_code'].'</td> 
      <td width=60 style="border:1px solid #c8c8c8;"> The date of </td> 
      <td width=100 style="border:1px solid #c8c8c8;">'.date('Y-m-d',$val[create_date]).'</td> 
      <td width=100 style="border:1px solid #c8c8c8;"> mark <br/> The name </td> 
      <td width=240 style="border:1px solid #c8c8c8;">'.$val[code].'/'.$val['orderid'].'<br/>'.$val['orderinfo']['user_name'].'</td> 
    </tr> 
    <tr bgcolor="White"> 
      <td width=60 style="border:1px solid #c8c8c8;"> number </td> 
      <td width=40 style="border:1px solid #c8c8c8;">3</td> 
      <td width=40 style="border:1px solid #c8c8c8;"> The weight of the </td> 
      <td width=150 style="border:1px solid #c8c8c8;">56.5</td> 
      <td width=40 style="border:1px solid #c8c8c8;"> Of the goods </td> 
      <td width=390 style="border:1px solid #c8c8c8;"> Bite, sucker bowl, learning to drink cup, dried fish oil </td> 
    </tr> 
    <tr bgcolor="White"> 
      <td width=110 style="border:1px solid #c8c8c8;"> service <br/> category </td> 
      <td width=200 style="border:1px solid #c8c8c8;"> Warehouse service </td> 
      <td width=110 style="border:1px solid #c8c8c8;"> service <br/> requirements </td> 
      <td width=280 style="border:1px solid #c8c8c8;"> And small box </td> 
    </tr> 
    <tr bgcolor="White"> 
      <td width=120 style="border:1px solid #c8c8c8;"><br/><br/> The customer <br/> note <br/><br/></td> 
      <td width=580 style="border:1px solid #c8c8c8;">'.$val['orderinfo']['beizhu'].'</td>     
    </tr> 
    <tr bgcolor="White"> 
      <td width=120 style="border:1px solid #c8c8c8;"><br/><br/><br/> The arrival of the goods <br/> situation <br/><br/><br/><br/></td> 
      <td width=580 style="border:1px solid #c8c8c8;"> What's the problem? GuoDian less than <br/> What's the problem? GuoDian less than <br/> What's the problem? GuoDian less than <br/><br/><br/><br/><br/><br/><br/><br/></td> 
    </tr> 
    </table> <br/><br/><br/><br/>
';  
 }
     $word->start();
     $filename = ' Export of pick list .doc';
     echo $html;
      $word->save($filename);

      // Type of file 
      header('Content-type: application/word');
      header('Content-Disposition: attachment; filename=" Export of pick list .doc"');
      readfile($filename);
      ob_flush();
      flush();
     exit();
// export word --end--


Related articles: