Hello, this is my first post here... and I'm stuck on COM objects.
I'm trying to open Word via PHP using code taken directly from php.net:
<?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;
?>
(from: <!-- m --><a class="postlink" href="http://us3.php.net/manual/en/class.com.php">http://us3.php.net/manual/en/class.com.php</a><!-- m -->)
I've also gone through this tutorial:
<!-- m --><a class="postlink" href="http://www.phpbuilder.com/columns/venkatesan20030501.php3">http://www.phpbuilder.com/columns/venka ... 30501.php3</a><!-- m -->
But I'm still stuck
When I run the above code, "Loaded Word, version 11.0" is outputted, and the task manager shows WINWORD.EXE running under the IUSER_mymachinename" account...
But Word is never made visible, no document is created or saved, and word does not quit (I have to end it in the task manager)
This seems to indicate that Word is in a sort of "read only" state... I can ask it what version it is, but I cannot tell it to do anything
The following also reports back "0" (another "read only" type of item)
echo '<br />'. $word->Documents->Count;
This is my first foray into COM objects, so I don't have any prior experience to draw upon... I'm hoping someone here can shed some light on this
Here's some additional info that might help:
PHP VERSION: 5.2.1
OS: WindowsXP pro
SERVER: IIS5 ("scripts and executables" is turned on)
COM php.ini settings:
[COM]
; path to a file containing GUIDs, IIDs or filenames of files with TypeLibs
com.typelib_file = "C:\WINDOWS\system32\activeds.tlb"
; allow Distributed-COM calls
com.allow_dcom = true
; autoregister constants of a components typlib on com_load()
com.autoregister_typelib = true
; register constants casesensitive
;com.autoregister_casesensitive = false
; show warnings on duplicate constant registrations
com.autoregister_verbose = true
I can't help but think I'm missing some configuration setting
Thanks in advance for any pointersThe important thing to note is that many OLE automation objects, including those provided by MS Office, are not intended for noninteractive use and won't work correctly when used non-interactively.
The crux of the problem is to do with these facts:
- When winword.exe encounters a problem it responds by popping up a dialogue box (invisibly) and waiting for the user to reply. This hangs the process indefinitely in this context.
- Microsoft IIS does not create a fully fledged registry profile for the user it is configured to log on as - this sometimes stops programs from operating correctly, even though they would otherwise work interactively as the same user.
Collectively, these problems mean that Winword.exe is not a suitable component for production server use. Consider one of the many commercial alternatives.
Mark
I'm trying to open Word via PHP using code taken directly from php.net:
<?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;
?>
(from: <!-- m --><a class="postlink" href="http://us3.php.net/manual/en/class.com.php">http://us3.php.net/manual/en/class.com.php</a><!-- m -->)
I've also gone through this tutorial:
<!-- m --><a class="postlink" href="http://www.phpbuilder.com/columns/venkatesan20030501.php3">http://www.phpbuilder.com/columns/venka ... 30501.php3</a><!-- m -->
But I'm still stuck
When I run the above code, "Loaded Word, version 11.0" is outputted, and the task manager shows WINWORD.EXE running under the IUSER_mymachinename" account...
But Word is never made visible, no document is created or saved, and word does not quit (I have to end it in the task manager)
This seems to indicate that Word is in a sort of "read only" state... I can ask it what version it is, but I cannot tell it to do anything
The following also reports back "0" (another "read only" type of item)
echo '<br />'. $word->Documents->Count;
This is my first foray into COM objects, so I don't have any prior experience to draw upon... I'm hoping someone here can shed some light on this
Here's some additional info that might help:
PHP VERSION: 5.2.1
OS: WindowsXP pro
SERVER: IIS5 ("scripts and executables" is turned on)
COM php.ini settings:
[COM]
; path to a file containing GUIDs, IIDs or filenames of files with TypeLibs
com.typelib_file = "C:\WINDOWS\system32\activeds.tlb"
; allow Distributed-COM calls
com.allow_dcom = true
; autoregister constants of a components typlib on com_load()
com.autoregister_typelib = true
; register constants casesensitive
;com.autoregister_casesensitive = false
; show warnings on duplicate constant registrations
com.autoregister_verbose = true
I can't help but think I'm missing some configuration setting
Thanks in advance for any pointersThe important thing to note is that many OLE automation objects, including those provided by MS Office, are not intended for noninteractive use and won't work correctly when used non-interactively.
The crux of the problem is to do with these facts:
- When winword.exe encounters a problem it responds by popping up a dialogue box (invisibly) and waiting for the user to reply. This hangs the process indefinitely in this context.
- Microsoft IIS does not create a fully fledged registry profile for the user it is configured to log on as - this sometimes stops programs from operating correctly, even though they would otherwise work interactively as the same user.
Collectively, these problems mean that Winword.exe is not a suitable component for production server use. Consider one of the many commercial alternatives.
Mark