找不到类“COM"
我一直在尝试在我的脚本中打开一个 word 文档,但我收到了同样的错误.
I've been trying to open a word document in my script, but I get receiving the same error.
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
部分删除分号.
I've tried to change php.ini
and remove the semicolons from COM
section.
[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
仍然出现同样的错误.
我在 mac 上使用 XAMMP
和基于 linux 的虚拟主机.
I'm using a XAMMP
on mac, and a linux based web hosting.
推荐答案
从 PHP 5.4.5 开始,COM 和 DOTNET 不再内置在 php 核心中.您必须在 php.ini 中添加 COM 支持:
From PHP 5.4.5, COM and DOTNET is no longer built into the php core.you have to add COM support in php.ini:
[COM_DOT_NET]
extension=php_com_dotnet.dll
否则,您将在错误日志中看到:致命错误:找不到类COM"
Otherwise you will see this in your error log: Fatal error: Class 'COM' not found
该扩展包含在适用于 Windows 的 php 5.4.5 中.
The extension is included with php 5.4.5 for Windows.
相关文章