I'm trying to open and read the contents of a Word document with PHO by using the COM function. But whenever i try to read the contents, then it gives me the following error:
Fatal error: Uncaught exception 'com_exception' with message 'Source: Microsoft Word
Description: This command is not available because no document is open.'
I have the following code:
$word = new \COM ( "word.application" ) or die ( "Could not initialise MS Word object." );
$word->Documents->Open ( realpath("test.doc" ) );
// Extract content.
$content = (string) $word->ActiveDocument->Content;
echo $content;
$word->ActiveDocument->Close(false);
$word->Quit();
$word = null;
unset($word);
I'm 100% sure that the Word document exists. I've checked this numerous times. The permissions on the file are set to Full Control
. So that can't be it either.
I've also read a comment on php.net. It said that IIS is causing a problem (i have that running). His solution was this:
In anyway, i still haven't got this working. Anyone any idea how could possibly fix this error...???
I just found the solution. The steps i talked about:
That works. But like i said, i couldn't find the Microsoft Office Word 97-2003
config. So this is what i've done in order to make it appear in the list.
So now you should be able to follow the steps from my first post. And PHP should then be able to read the docs without any trouble.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With