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.