我在PHP中使用COM來在Windows Server 2003中成功操作MS Word 2003,但是在Windows 2008服務器中出現相同的代碼。我已將用戶更改爲管理員,但仍發生相同的錯誤。在Windows 2008服務器上PHP COM失敗
對於下面的代碼:
<?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;
?>
我得到這個錯誤:
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