tags:

views:

24

answers:

1

I use COM in PHP to manipulate MS Word 2003 with success in Windows server 2003, but the same code are broken in Windows 2008 server. I've changed the user to administrator but still the same error occurred.

For the code below:

<?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("C:\\wamp\\www\\iword\\Useless test.doc");

//closing word
$word->Quit();

//free the object
$word = null;
?>

I got this error:

Loaded Word, version 11.0 Fatal error: Uncaught exception 'com_exception' with message 'Source: Microsoft Word
Description: Command failed' in C:\wamp\www\iword\index.php:14 Stack trace: #0 C:\wamp\www\iword\index.php(14): variant->SaveAs('C:\wamp\www\iwo...') #1 {main} thrown in C:\wamp\www\iword\index.php on line 14