This article mainly introduces php code examples for exporting word format data. if you need code, refer to this section:
A php document export class
Example:
The code is as follows:
/**
* Word document generation class
*
*/
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 );
}
}
// Export the program file
// Export --- start ---
Require SITE_ROOT. 'include/word. class. php'; // put the class file in the include folder under the root directory
$ Word = new word ();
// Enter the query data in 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 ['rapinfo'] = $ 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 operation Ticket No. |
'. $ Val ['box _ Code'].' |
Date |
'. Date ('Y-m-D', $ val [create_date]).' |
Mark Name |
'. $ Val [code].'/'. $ val ['orderid'].' '. $ Val ['orderinfo'] ['User _ name'].' |
Number of parts |
3 |
Weight |
56.5 |
Product Name |
Bit, suction bowl, drinking cup, dried fish oil |
Service Category |
Warehouse Service |
Service Requirements |
Binning case |
Customer Remarks
|
'. $ Val ['orderinfo'] ['beizhu'].' |
Arrival Situation
|
What's the problem? Failed What's the problem? Failed What's the problem? Failed
|
';
}
$ Word-> start ();
$ Filename = 'picking ticket export .doc ';
Echo $ html;
$ Word-> save ($ filename );
// File type
Header ('content-type: application/word ');
Header ('content-Disposition: attachment; filename = "picking ticket export .doc "');
Readfile ($ filename );
Ob_flush ();
Flush ();
Exit ();
// Export word -- end --