Php export to generate the word method this article describes how to export and generate the word in php. We will share this with you for your reference. The details are as follows:
PHP export word
(1) first, preview the html page, sample object, and define the data to be exported.
(2) click the download page to pass a value to the id (any value can be used for determination only). if the id has a value, the output buffer file is saved as the word format.
(3) Click Download. (if an image is saved as a word, use the absolute path to display it normally in the saved word)
(4) Disable Cache output
Word_con.php preview the html file to be exported
Start (); // define the start of the data to be saved} include ('Word _ show. php'); if (@ $ _ GET [id]! = '') {$ Word-> save('word_c.doc '); // defines the end of the data to be saved, at the same time, save the data to the word} if (@ $ _ GET [id] = '') {// The x in the hyperlink is only used to pass a value and confirm the download, no other actual yi?>Click to jump to the download page
Word_fun.php export word-related functions
';} Function save ($ path) // defines the end of the data to be saved, and saves the data to word. // the data to be saved must be limited to start () of this class () and save () {print""; $ Data = ob_get_contents (); // return the internal buffer content to convert the output to the string ob_end_clean (); // end the output buffer, clean (erased) output Buffer and disable output buffer $ this-> wirtetoword ($ path, $ data);} function wirtetoword ($ fn, $ data) // save the data in binary format to word {$ fp = fopen ($ fn, "wb"); fwrite ($ fp, $ data ); fclose ($ fp) ;}}?>
Word_show.php connects to the database and queries related data
I hope this article will help you with PHP programming.
Related articles:
Php uses phpword to generate word documents
Generate a Word document on the web page in the php program and provide the downloaded instance code.
Three methods for generating word documents in PHP