Php word document generation instance

Source: Internet
Author: User
It is much easier for php to generate word documents than excel. just set the header information and we can directly use fopen for read operations. The following are several examples. php directly uses fopen to generate the core code as follows: htmlx... it is much easier for php to generate word documents than excel. just set the header information and we can directly use fopen for read operations. The following are several examples.

Php directly uses fopen to generate the core code as follows:

'. Your stored data .'

The code is as follows:

 ' . $data . '';    if (emptyempty($fileName)) $fileName = date('YmdHis') . '.doc';    $fp = fopen($fileName, 'wb');    fwrite($fp, $data);    fclose($fp);}?>

Example:

 Use php to create word documentsUse php to create a word document by phprm.com
   

If you open Word.doc and see the introduction here, the word document is created successfully.

Copyright:
Www.phprm.com

'; Word ($ str) ;?>

For ease of use, we organize it into a class file. the code is as follows:

 ';    }    function save($path) {        print "";        $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 code is as follows:

 start();?>

Querying mysql data to generate word is also very simple. we only need to connect to the database, and then store the database content in the $ word field of the class, and then use $ word-> start (); generate.

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.