#native_company# #native_desc#
#native_cta#

COM Functions in PHP4 Page 2

By Alain M. Samoun
on October 3, 2000

Using PHP4 COM functions with MS Word

Now, we have all we need to start with the first code example:

<?php

#*********************************************************

# This example, slightly modified from the Zend site,

#  will open an instance of 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>"

#Another way to get the version using com_get

$testversion com_get($word->application,version);

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 see the word document,

#then close word manually

$word->Quit(); 

#Comment if you want to see the word document, then close 

?>



If you study this example for a few minutes using the OLE documentation that comes with
Word, you will learn practically all you need to write your own program.