找不到"COM"类 [英] Class 'COM' not found
问题描述
我一直试图在脚本中打开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
,仍然出现相同的错误.
and still getting the same error.
我在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.
这篇关于找不到"COM"类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!