In PHP development, how does PHP implement HTML Word with each other? Is there any way? The following is to introduce PHP into Word in the HTML method, this is tested, this method is a bit bad, HTML page code to write in PHP, but somehow can run, see the program '; }function Save ($path) {echo]"; $data = Ob_get_contents ();} function Wirtefile ($FN, $data) {$fp =fopen ($fp, $data); Fwrite ($fp, $data);}} $html = '
name
gender |
age |
hobby |
remarks |
Zhang San |
man |
32 |
soccer |
|
John Doe |
man |
basketball |
|
" /table>
';///Bulk Generate//for ($i =1; $i <3; $i + +) {$word = new word (); $word->start (); $wordname = ' personal test php generated Word.doc '; echo $html; $ Word->save ($wordname); header (' Content-type:application/word '); header (' Content-disposition:attachment; Filename= '. $wordname. '); /readfile ($wordname); Ob_flush ()//flush cache flush before each execution ();//}?> below to share a piece of code PHP implementation of Word to HTML method to perfect solve, office to PDF or HTML , it is best to use Windows Office software, LibreOffice not perfect conversion, WPS no API. First confirm that the COM module is not open, phpinfo inside if there is com_dotnet module, the description has been turned on, if not, modify PHP.ini, The code is as follows: Com.allow_dcom = True before the comment is removed, restart is OK, the official PHP website said, php5.4.5 before the COM module is built-in, in fact, is not necessarily all, the official website of the PHP 5.3.39,com module is not built-in. If not the built-in module, PHP.ini Plus, the premise of your Ext folder, there is the extension code as follows: Extension=php_com_dotnet.dll and then restart it ok. function word2html ($wordname, $ HTMLName) {$word = new COM ("Word.Application") or Die ("Unable to instanciate word"); $word->visible = 1; $word Documents->open ($wordname); $word->documents[1]->saveas ($htmlname, 8); $word->quit (); $word = Null;unset ($word);} word2html (' D:/www/test/6.docx ', ' d:/www/test/6.html '); Note: 1. Converted out of HTML, view the source code, the more chaotic 2. The winword.exe3 is called during the conversion. If the page is loading, rename the document, and then turn it back on. The above is the whole content of this article, interested friends can try their own, if there is a better way to achieve the HTML Word transfer, welcome to share to everyone. Recommended reading: Common analytical techniques for infinite pole classification of data sorting in PHP
|