Monday, May 13, 2013

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;
?>
 Create an object of COM. 
  1. - Set the visibility of the file to 1 
  2. - Invoke the function Add() for creation of a document 
  3. - Insert the text into the document 
  4. - Save the file as the destination file 
  5. - 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(); 
?>

1 comment:

  1. I just couldn't leave your website before telling you that I truly enjoyed the top quality info you present to your visitors? Will be back again frequently to check up on new posts. Lifeguard recertification

    ReplyDelete