Window|word COM functions in PHP4 (Windows)
Alain M. Samoun
Introduction
The built-in COM functionality of PHP4 is quite attractive for some to us programming in the Win32 environment. So far, there isn't much documentation on the subject. This is short article would explain how to use COM in real PHP4 programming with three the using MS office Word and Excel programs and the Adobe Distiller program. The COM technology has been developed by Microsoft for several years, under different. As far as this article are concerned, the words OLE, OLE Automation, ActiveX and COM are all the Same:they designate a EN capsulated Piece of code (the Object) that performs some functions for a Windows application. PHP4 COM connects to the object (instantiate object) and uses its methods and properties.
If you are want to reproduce the following examples, this is my configuration:
Windows 98-ms Office 2000
Apache 1.3.9 Windows
PHP4.02 Dev (08-20-00) Running as CGI
COM tags in PHP4
Lets start with the specific information to use the COM functions with PHP4. To instantiate a component, one needs the "new" operator and the "OLE programmatic identifiers" of the object:
<?php
$instance = new COM ("$identifier");
?>
Since COM is a reserved class name in PHP4, it passes the object's identifier to the constructor. Now so we have instantiated the component, we can easily reach its methods and properties, using the OOP class. For example:
<?php
?>
It ' s that simple!
There are two tag functions for PHP4 COM This are when the OOP used construct ' t doesn. (in the case of PHP syntax problems, with the names and values of properties with invalid characters, like dot or parenthe SIS):
<?php
?>
Finally, PHP4 also supports DCOM to create a instance of a remote computer:
<?php
$Instance = new COM (string "Component name", string "remote_server_address");
?>
Note:there is a DCOM directive to set in the PHP configuration. PHP developers may add DCOM support to Unix in the future. That's all, there are No. functions to remember!
Identifiers, methods and properties.
Identifiers are strings like:
For MS Word: "Word.Application" or "Word.application.9"
MS Excel: "Excel.Application" or "Excel.Sheet"
ADOBE Acrobat: "Exch.application" or "Pdfdistiller.pdfdistiller"
As the last identifier name indicates, it isn't always easy to know the right name for the object. If you don't have access to a VBA doc, you can look at the Windows registry (Start-run regedit) and look in the HKEY_CL Asses_root Folder:scan down until the "end of the" extensions list, you'll then reach the application names. The COM Identifiers available in your machine, are the folders with the CLSID subfolders.
The application program is should document its COM methods and properties. In the case of Office, start the application, then open the Visual Basic Editor with the <ALT+F11> short cut ke Y and select the Objects Editor <f2>. Enter a name of type or properties for the application ' s library. Then, select a class or member and right click on the member name in the next window below. You'll get the "description for" class or member by selecting Help. You can also consult MSDN. An example for Excel is:http://msdn.microsoft.com/library/officedev/off2000/xltocobjectmodelapplication.htm
Using PHP4 COM functions with MS Word
Now, we have all we need to start with the ' the ' the ' the ' the ' the ' the ' the '
<?php
#*********************************************************
# This is example, slightly modified from the Zend site,
# would open an instance to Word with a new
# Document with the name ' useless Test.doc ' and the line:
# "This is a test2 ..." typed inside.
#*********************************************************
#Instantiate the Word component.
$word = new COM ("Word.Application") or Die ("Unable to instantiate word");
#Get and print its version
Print "Loaded Word, Version {$word->version}<br>";
Print "Version using Com_get (): $testversion <BR>";
#Make it visible in a window
$word->visible = 1;
#Open a new document
$word->documents->add ();
#Write something
$word->selection->typetext ("This is a test ...");
#Now Save the document
$word->documents[1]->saveas ("Useless test.doc");
#Comment Next line if you want to the Word document,
#then Close Word manually
$word->quit ();
#Comment If you want to the Word document, then close
?>
If You are study This example for a few minutes using the OLE documentation so comes with Word, your would learn practically a ll you need to write your own.
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.