PHP Open COM Component read Word file ____php

Source: Internet
Author: User
1. Open COM option in php.ini First, com.allow_dcom = True
2. My environment here is php5.4.7,php 5.4.5, com/dotnet module has become a separate extension, so need to configure Extension=php_com_dotnet.dll in php.ini, if PHP version< 5.4.5 is not needed. Otherwise, it may be an error Fatal Error:class ' COM ' not found.
The configuration method is: Simply add Extension=php_com_dotnet.dll to the extended list

3. It is also necessary to understand that, although the COM component is also a DLL extension, it is not a php extension, so it is wrong to copy the Senc.dll to the Php/ext directory and then add it to the php.ini, which PHP does not recognize.


Establish an index to the new COM component

$word = new COM ("Word.Application") or Die ("Can ' t start word!");
Displays the version number of Word that is currently in use
echo "Loading Word, v. {$word->version}";
Set its visibility to 0 (false), if you want it to open at the front end, use 1 (true)
To open the application in the forefront, use 1 (true)
$word->visible = 0;

Call a document.
$word->documents->open (DirName (__file__). /1.doc ");
Reading the contents of a document
$test = $word->activedocument->content->text;
Echo $test;
echo "";
Change the variables in the document that need to be changed
$test =str_replace ("<{variable}>", "This is 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 ("2.doc");
Turn off connection to COM components
$word->quit ();

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.