2009-11-11 57 views
1

我在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

回答

0

在猜測,我會說你有一個權限問題,你不能寫入到該目錄下,我會建議從VBA中嘗試相同的代碼來縮小可能的失敗點。

1

Apache服務需要1個窗口帳戶有權限網絡來啓動它。簡單的你需要通過命令啓動apache來測試。不要通過服務啓動Apache。