Example of using php to create a word document

Source: Internet
Author: User
The following is an example of using php to create a word document. it is very simple to create a word file processing class. we just need to load it and then create a class regeneration achievement. The example code is as follows :? Phpinclude (quot... the following is an example of using php to create a word document. it is very simple to create a word file processing class. we only need to load it and then create a class regeneration achievement. The example code is as follows:

 start();?>

Directly use PHP to create a wordfile. if you open Word.doc and see the introduction here, it means that the word file has been created successfully. in any operating system, you can use PHP to generate a Word file directly!

Even if you haven't installed word, you can also generate word files. of course, you can use word, wps or other software to open the generated word files.

Usage: first, use $ word-> start () to generate a word file. then, you can output any HTML code, whether it is read from the file or written here, it does not matter whether HTML is output directly here.

After the output is complete, use the $ word-> save ($ path) method. $ path is the name of the word file you want to generate. you can provide the complete path, after you use the $ word-> save () method, any output after this is irrelevant to the word file, that is, the word generation is complete, after that, it will be pulled in the same way as you normally use php. whatever you want to output, it will be output directly in the browser rather than written into the word.

This is a very interesting method I have come up with. its implementation method is surprisingly simple, and it avoids dependency on the windows environment. haha, is it very interesting? Enjoy it.

The example code for creating a Word document using php is as follows:

 Save ("data.doc"); // save the word and end with. echo'Directly use php to create word documentsDid I directly create a word document using php to generate a word? Check whether data.doc exists in your Directory!
If you are using windows and have installed word, you can view

Here ';?>

The code for the word. php file is as follows:

 ';} Function save ($ path) {print""; $ Data = ob_get_contents (); ob_end_clean (); $ this-> wirtefile ($ path, $ data);} // open-source code phprm.com function wirtefile ($ fn, $ data) {$ fp = fopen ($ fn, "wb"); fwrite ($ fp, $ data); fclose ($ fp) ;}}?>


Permanent link:

Reprint at will! Include the article address.

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.