PHP tutorial PHP HTML Word transfer method sharing

Source: Internet
Author: User
Tags php class php website
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 " /table>
gender age hobby remarks
Zhang San man 32 soccer
John Doe man basketball
';///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
  • 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.