Php code for exporting data in word format _ php instance

Source: Internet
Author: User
Tags export class php code examples
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 --

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.