How PHP reads the contents of a Word document, how to handle it

Source: Internet
Author: User
How PHP reads the contents of a Word document
Establish an index to the new COM component
$word = new COM ("Word.Application") or Die ("Can ' t start word!");
Displays the version number of the word that is currently in use
echo "Loading Word, v. {$word->version}
”;
Set its visibility to 0 (false), use 1 (true) if you want to make it open in the front-end
To open the application in the forefront, use 1 (true)
$word->visible = 0;
Hit a document.
$word->documents->open ("E:\wamp\www\oa\121.doc");
Read Document Contents
$test = $word->activedocument->content->text;
Echo $test;
echo "
";
Change the variable you want in your document
$test =str_replace ("<{variable}>", "This is a variable", $test);
Echo $test;
$word->documents->add ();
Add text to a new document
$word->selection->typetext ("$test");
Save the document in the directory
$word->documents[1]->saveas ("E:/wamp/www/oa/121.doc");
To close a connection to a COM component
$word->quit ();
?>
Error Reporting
Fatal error:uncaught exception ' com_exception ' with message ' Failed to create COM object ' Word.Application ': Îþð§µäóï ¨ ' In E:\wamp\www\oa\newfile.php:3 Stack trace: #0 E:\wamp\www\oa\newfile.php (3): com->com (' Word.applicatio ... ') #1 { Main} thrown in E:\wamp\www\oa\newfile.php on line 3
I want to ask a COM is this one what thing AH!! Where is it
$test =str_replace ("<{variable}>", "This is a variable", $test); How do you write the variables here?


------Solution--------------------
COM is an information service component of Microsoft

Your program runs on the condition that your server has a version of Word97 to word2003 installed
------Solution--------------------
I used to try to do PDF to Word when the test issued by PHP to read and write word is slow I suggest not to do I was using Win7+apache+php+mysql, the browser tested ie,360, the window of the world
  • 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.