(From?) PHP 5.4.5 for Windows:
If you are seeing this in your error log:
Fatal error: Class 'COM' not found
You require this in php.ini:
[PHP_COM_DOTNET]
extension=php_com_dotnet.dll
Previously it was compiled as built-in on the Windows build. I assume this has happened because the com extension can now be built as a shared component.
COM および .Net (Windows)
- 導入
- インストール/設定
- 定義済み定数
- エラーおよびエラー処理
- 例
- COM — COM クラス
- DOTNET — DOTNET 説明
- VARIANT — VARIANT クラス
- COM関数
- com_addref — コンポーネントの参照カウンタを増やす [非推奨]
- com_create_guid — グローバルユニーク ID (GUID) を生成する
- com_event_sink — COM オブジェクトのイベントを PHP オブジェクトに接続する
- com_get_active_object — すでに実行中の COM オブジェクトのインスタンスへのハンドルを返す
- com_get — COM コンポーネントのプロパティの値を得る [非推奨]
- com_invoke — COM コンポーネントのメソッドをコールする [非推奨]
- com_isenum — COM オブジェクトが IEnumVariant インターフェイスを実装しているかどうかを示す [非推奨]
- com_load_typelib — タイプライブラリを読み込む
- com_load — COM コンポーネントへの新規リファレンスを作成する [非推奨]
- com_message_pump — COM メッセージを処理し、timeoutms ミリ秒の間待つ
- com_print_typeinfo — ディスパッチインターフェイスのために、PHP のクラス定義を出力する
- com_propget — com_get のエイリアス
- com_propput — com_set のエイリアス
- com_propset — com_set のエイリアス
- com_release — コンポーネントリファレンスカウンタを減らす [廃止]
- com_set — COM コンポーネントのプロパティに値を代入する
- variant_abs — variant の絶対値を返す
- variant_add — 2 つの variant 値を「加算」し、結果を返す
- variant_and — 2 つの variant の論理積を計算し、結果を返す
- variant_cast — variant を、別の型の新しい variant に変換する
- variant_cat — 2 つの variant 値を連結し、その結果を返す
- variant_cmp — 2 つの variant を比較する
- variant_date_from_timestamp — Unix タイムスタンプを、日付形式の variant で返す
- variant_date_to_timestamp — 日付/時刻の variant 値を Unix タイムスタンプに変換する
- variant_div — 2 つの variant の除算結果を返す
- variant_eqv — 2 つの variant のビット値が等しいかどうかを調べる
- variant_fix — variant の整数部を返す
- variant_get_type — variant オブジェクトの型を返す
- variant_idiv — variants を整数に変換し、除算の結果を返す
- variant_imp — 2 つの variant のビット implication を行う
- variant_int — variant の整数部を返す
- variant_mod — 2 つの variant の除算を行い、剰余を返す
- variant_mul — 2 つの variant の乗算を行い、その結果を返す
- variant_neg — variant の論理否定演算を行う
- variant_not — variant のビット否定演算を行う
- variant_or — 2 つの variant の論理和を計算する
- variant_pow — 2 つの variant の累乗計算を行い、その結果を返す
- variant_round — 指定した桁で variant を丸める
- variant_set_type — variant を「その場で」別の型に変換する
- variant_set — variant オブジェクトに新しい値を代入する
- variant_sub — 左の variant から右の variant を引き、その結果を返す
- variant_xor — 2 つの variant の排他的論理和を計算する
robert dot johnson at icap dot com ¶
10 months ago
Dave Bachtel ¶
3 years ago
Hello everybody!
Here is some helpful advice for people attempting to use COM with Microsoft MapPoint 2006 or 2009 with PHP.
If you are using apache, it MUST be running under the same credentials as a desktop user that has already installed/run mappoint or modifiy the service and select the "Allow Service to Interact with Desktop" option. Otherwise, it won't work due to the EULA popup having to be accepted. Mappoint 2004 works just fine, this only applies to 2006 and 2009.
For troubleshooting, the error that appears in the System event viewer is:
The server {31851F82-AFE6-11D2-A3C9-00C04F72F340} did not register with DCOM within the required timeout.
The error generated by PHP, if you happen to get lucky and let the COM() function timeout by cranking up set_time_limit() timeout is:
<?php
set_time_limit(1000) ;
$mapoint = new COM("MapPoint.Application") or die("Unable to instantiate Mappoint COM object");
?>
Generates:
Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `MapPoint.Application': Server execution failed ' in [somefile.php]:9 Stack trace: #0 [somefile.php](9): com->com('MapPoint.Applic...') #1 {main} thrown in [somefile.php] on line 9
Also, if you have multiple versions of MapPoint installed, you will need to run:
c:\path\to\mappoint\MapPoint.exe /registerserver
(using the correct folder path) to select the right version of the com object to use. Gooood luck!
Anonymous ¶
3 years ago
Add hyperlink at a Word Document's bookmark
<?php
// Create COM instance to word
function clsMSWord($Visible = false)
{
$this->handle = new COM("word.application") or die("Unable to instanciate Word");
$this->handle->Visible = $Visible;
}
function WriteHyperlink($Bookmark,$Path,$Text)
{
$objBookmark = $this->handle->ActiveDocument->Bookmarks($Bookmark);
$range = $objBookmark->Range;
$objHyperlink = $this->handle->ActiveDocument->Hyperlinks;
$objHyperlink->add($range,$Path,"","",$Text);
}
?>
acsandeep at gmail dot com ¶
4 years ago
If you are trying to get the properties of a Word document opened via COM object, you may need to define some constants in your script like so.
<?php
define('wdPropertyTitle', 1);
define('wdPropertySubject', 2);
define('wdPropertyAuthor', 3);
define('wdPropertyKeywords', 4);
define('wdPropertyComments', 5);
define('wdPropertyTemplate', 6);
define('wdPropertyLastAuthor', 7);
$word = new COM("word.application") or die ("Could not initialise MS Word object.");
$word->Documents->Open(realpath("Sample.doc"));
$Author = $word->ActiveDocument->BuiltInDocumentProperties(wdPropertyAuthor);
echo $Author;
?>
long2hu3 ATT yahoo DOTT com ¶
4 years ago
When you work with MS Excel, Word, ... and other applications, never forget that COM doesn’t know their predefined constants, thus if you want to do sth. that would look like this in VB:
With myRange.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
you should either use numbers or define constants above, like this:
<?php
define('xlEdgeBottom', 9);
define('xlContinuous', 1);
define('xlThin', 2);
define('xlAutomatic', -4105);
$ex = new COM("Excel.Application", NULL, CP_UTF8) or Die ("Did not instantiate Excel");
$wb = $ex->Application->Workbooks->Add();
$ws = $wb->Worksheets(1);
$xra = $ws->Range("A1:A6");
$bs = $xra->Borders(xlEdgeBottom);
$bs->LineStyle = xlContinuous;
$bs->Weight = xlThin;
$bs->ColorIndex = xlAutomatic;
?>
It is pointless to try to use text strings, i.e.
<?php
$bs = $xra->Borders('xlEdgeBottom');
$bs->Weight = 'xlThin';
?>
this will cause an error: Unable to set property Weight of class Border ...
ilayansmano at gmail dot com ¶
4 years ago
Extracting text from Word Documents via PHP and COM
<?php
$word = new COM("word.application") or die ("Could not initialise MS Word object.");
$word->Documents->Open(realpath("Sample.doc"));
// Extract content.
$content = (string) $word->ActiveDocument->Content;
echo $content;
$word->ActiveDocument->Close(false);
$word->Quit();
$word = null;
unset($word);
?>
