Home>Article>PHP Framework> How to export word with thinkphp

How to export word with thinkphp

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼 Original
2019-08-22 16:34:18 4795browse

How to export word with thinkphp

thinkphp needs to introduce the Wordmaker.class.php class file to export word, and use this class file to generate and export the word document. The following describes the implementation process:

Create a new WordController.class.php file in the controller folder of Thinkphp as a controller for generating word.

How to export word with thinkphp

How to export word with thinkphp

Put the Wordmaker.class.php class file under the Util folder of the Thinkphp directory for the following steps to import it using the import method class file.

How to export word with thinkphp

Related recommendations: "ThinkPHP Tutorial"

Create a new WordMake method in the wordController controller to generate word documents. In the WordMake method, you need to load the Wordmaker.class.php class file first. The code is as follows:

How to export word with thinkphp

#Write code in the WordMake method to convert html content into word document content. The code is as follows:

How to export word with thinkphp

#Write code and use the WordMake method to generate a word document. Create a new execution method outword() for exporting word documents.

How to export word with thinkphp

Get the content of the word document to be generated in the outword() method (for the convenience of testing, a piece of HTML code is used here and saved in the $content variable), through WordMake The method generates a word document and saves it in the root directory with the document name "Test". The code is as follows:

How to export word with thinkphp

#Run the code in the browser and view the generated word document.

By viewing the content of the word document, it can be seen that the red text "

This is word content.
" has been successfully saved in the file. , and export the word document.

How to export word with thinkphp

How to export word with thinkphp

How to export word with thinkphp

The above is the detailed content of How to export word with thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How thinkphp uses redis Next article:How thinkphp uses redis