40

我一直在尝试在我的脚本中打开一个 word 文档,但我收到了同样的错误。

 Fatal error: Class 'COM' not found in /Applications/XAMPP/xamppfiles/htdocs/**/**.php on line 3

我的代码:

<?php

$word = new COM("word.application") or die("Unable to instantiate Word"); 

$word->Visible = 1; 


$word->Documents->Open("wordfile.docx");
$temp = $word->Dialogs->Item(228); // returns wdDialogToolsWordCount dialog object
$temp->Execute();   //updates the word count
$numwords = $temp->Words(); //gets the words out of it

echo 'Word count = '.$numwords;

$word->Quit(); 

?>

我试图更改php.ini和删除COM部分中的分号。

[com]
path to a file containing GUIDs, IIDs or filenames of files with TypeLibs
com.typelib_file = 
allow Distributed-COM calls
com.allow_dcom = true
autoregister constants of a components typlib on com_load()
com.autoregister_typelib = true
register constants casesensitive
com.autoregister_casesensitive = false
show warnings on duplicate constat registrations
com.autoregister_verbose = true 

并且仍然得到同样的错误。

我正在使用一个XAMMPon mac 和一个基于 linux 的网络托管。

4

4 回答 4

150

从 PHP 5.4.5 开始,COM 和 DOTNET 不再内置在 php 核心中。您必须在 php.ini 中添加 COM 支持:

[COM_DOT_NET]
extension=php_com_dotnet.dll

否则,您将在错误日志中看到:致命错误:找不到类“COM”

该扩展包含在适用于 Windows 的 php 5.4.5 中。

于 2012-08-21T07:43:53.457 回答
7

请参阅COM 要求

COM 函数仅适用于 Windows 版本的 PHP。

.Net 支持需要 PHP 5 和 .Net 运行时。

于 2012-05-21T00:21:01.727 回答
0

I'm using PHP version 5.6.14 for one of my projects, the php_com_dotnet.dll file is included in the ext/ directory but the same is not added in the php.ini file. So, you need to add the "extension=php_com_dotnet.dll" line in the php.ini file. Check phpinfo() in the browser to make sure that it is enabled. Hope, this might help someone.

于 2020-06-24T18:58:30.613 回答
-1

Using Windows Server2019, Apache 32Bit (C:\Apache24), PHP 32Bit (C:\PHP)

As jross wrote: Full path to php_com_dotnet.dll was the solution for me (extension=C:\PHP\ext\php_com_dotnet.dll).

于 2020-04-09T10:09:01.697 回答