COM Word.Application in PHP

1

I am creating a word document from a template using a web app I wrote in PHP (Yii Framework) using COM and I receive an error when I try to release the object

    $word = new COM("Word.Application") or die("Unable to instantiate Word");
    ....
    $word->Quit(); 
    $word->Release(); 
    $word = null; 

When I use the Release method I get Error [0x800706be] The remote procedure call failed. There are no errors in the Event Viewer and in fact it reports that Microsoft Office session lasted 17 seconds and session ended normally, word is not still active in task manager and the document is generated as per the code. My question is do I need to use the Release method - is Quit and setting the object to null sufficient? This is running on an Apache Server using PHP Version 5.4.7.

php
com
ms-word
asked on Stack Overflow Feb 6, 2013 by smuzoen • edited Feb 6, 2013 by (unknown user)

1 Answer

2

This works:

$word = new COM("Word.Application") or die("Unable to instantiate Word");
...
$word->Quit();
$word = NULL;
unset($word);

Further explanation:

The Release command is not necessary so remove that and be sure to use the unset($word); command to destroy the variable once it's no longer needed

answered on Stack Overflow Apr 6, 2013 by Steve T • edited Apr 18, 2013 by Steve T

User contributions licensed under CC BY-SA 3.0