Added in PHP 4 is support for COM on Windows operating systems. COM, which
stands for Component Object Module, is a technology developed by Microsoft to control its applications via a programming language, notably Visual Basic. It is related to other Microsoft technologies such as OLE (Object Linking and Embedding) and ActiveX.
Microsoft has defined every function and attribute that an application—such as Word or Excel—has as an object with methods and properties. Using the proper notation, you can then control the application with Visual Basic or, in this case, PHP. You begin by creating a new object using the name of the application and PHP’s com() function.
$word = new COM(‘word.application’);
You can set the application to run either visibly on the computer or invisibly by setting the Visible value (this step is not required).
$word->Visible = 1; // Visible
Once the application is running, you begin by creating a new document.
$word->Documents->Add();
Now, in the case of a Word document, you can start adding text to the page.
$word->Selection->TypeText(‘http://kiran.org.in’);
Finally, save the document and quit Word.
$word->Documents[1]->SaveAs(‘kiran.doc’);
$word->Quit();
As you can see from those lines, accessing COM with PHP is fairly simple and direct; the most complicated issue will be understanding what objects are available in an application and how exactly you should refer to them. You have several options:
◆ Pick up a book that covers COM for the specific application you are using.
◆ Learn Visual Basic, will help u with knowing the different objects available.
◆ Use the Visual Basic Help aspect of the application itself.
◆ Search the Internet!
I’ve taken all of these steps, and still, understanding how to do certain things can be a challenge. But if you work with Windows a lot, mastering this skill can be very useful.
For some assistance, once you have opened an application, like Word or Excel, press Alt+F11 to bring up the Visual Basic editor. Then press F2 to view the
Object Browser. By clicking and viewing the different elements in the Object Browser, you can see how the different objects, methods, and attributes you’ll
need relate. To get a jump-start on understanding COM for an application, use the Visual Basic Help application.
- Kiran's blog
- 534 reads













Post new comment