Explain how to access a COM object from within my PHP page.
To access COM object from PHP page, COM class can be made use of.
$obj = new COM("Application.ID")
Example:<?php
// starting word
$ pad = new COM("pad.application") or die("Unable to instantiate pad ");
echo "Loaded Notepad, version {$ pad ->Version}\n";
//bring it to front
$ pad ->Visible = 1;
//open an empty document
$ pad ->Documents->Add();
//do some weird stuff
$ pad ->Selection->TypeText("This is a test...");
$ pad ->Documents[1]->SaveAs("Sample test.doc");
//closing word
$ pad ->Quit();
//free the object
$ pad = null;
?>
Explain how to access a COM object from within my PHP page.
The following is the process:
- Create an object of COM.
- Set the visibility of the file to 1
- Invoke the function Add() for creation of a document
- Insert the text into the document
- Save the file as the destination file
- Exit the process
The code is furnished here under.
<?
$word=new COM("word.application") or die("Cannot start word application");
print "The word version is ($word->Version)\n";
$word->visible =1;
$word->Documents->Add();
$word->Selection->Typetext("Sample_text");
$word->Documents[1]->SaveAs("samplefile.doc");
$word->Quit();
?>