|
Posted by Jochem Maas on 05/17/05 17:51
bob pilly wrote:
> Hi all!
>
> I am trying to start word using com and php and having
> problems. I am running php 5.04 and apache 2.054 on
> windows. I have used a simple example from the php
> site but cant get it working.
>
> |<?php
> // starting word
> $word = new COM("word.application") or die("Unable to
> instantiate Word");
> echo "Loaded Word, version {$word->Version}\n";
>
> //bring it to front
> $word->Visible = 1;
>
> //open an empty document
> $word->Documents->Add();
>
> //do some weird stuff
> $word->Selection->TypeText("This is a test...");
> $word->Documents[1]->SaveAs("Useless test.doc");
>
> //closing word
> $word->Quit();
>
> //free the object
> $word = null;
> ?>
>
> i have called this page testcom.php but when i try and
> view it with a clients browser i get this error:
>
> [client xxx.xxx.xxx.xxx] PHP Fatal error: Uncaught
> exception 'com_exception' with message 'Failed to
> create COM object `Word.application': Invalid
> syntax\r\n' in C:\\Program Files\\Apache
> Group\\Apache2\\htdocs\\testcom.php:3\nStack
> trace:\n#0 C:\\Program Files\\Apache
> Group\\Apache2\\htdocs\\testcom.php(3):
> com->com('Word.applicatio...')\n#1 {main}\n thrown in
> C:\\Program Files\\Apache
> Group\\Apache2\\htdocs\\testcom.php on line 3
>
> |
> Has anyone seen this error before or know what it
> means? Or if possible does anyone know of any good
> docs on using com with php?
this is not a COM specific error, you're trying to create
a new COM object and that fails - rather than return something
that evaluates to false the constructor for the COM object (
or something it is trying to call) is throwing a Exception...
('throwing' of) exceptions (and logically also the 'catching'
of them) are new concepts in PHP5.
try like it this and see whether something more useful error msg
is output:
<?php
// this is PHP5 only!
try {
// starting word
$word = new COM("word.application");
echo "Loaded Word, version {$word->Version}\n";
//bring it to front
$word->Visible = 1;
//open an empty document
$word->Documents->Add();
//do some weird stuff
$word->Selection->TypeText("This is a test...");
$word->Documents[1]->SaveAs("Useless test.doc");
//closing word
$word->Quit();
//free the object
$word = null;
}
catch (com_exception $e) {
echo "something bad happened with COM:<br />", $e->__toString();
}
catch (Exception $e) {
echo "something bad happened:<br />", $e->__toString();
}
?>
lookup 'try'/'catch'/'throw', 'exception' in the manual (php5 specific
areas).
>
> Thanks in advance for any help!!
>
> Cheers
>
> Bob
>
>
>
>
>
> ___________________________________________________________
> Yahoo! Messenger - want a free and easy way to contact your friends online? http://uk.messenger.yahoo.com
>
Navigation:
[Reply to this message]
|