php的com組件
⑴ php中有個com組件,它裡面都有哪些屬性和方法可以調用呢
先到PHP.INI中打開COM選項,com.allow_dcom = true
PHP 5.4.5後,com/dotnet 模塊已經成了單獨的擴展,所以需要在PHP.ini中配置extension=php_com_dotnet.dll,如果PHP VERSION<5.4.5 則不需要。否則的話,可能就是報錯 Fatal error: Class 'COM' not found 了
配置方法為:只需在擴展列表裡添加extension=php_com_dotnet.dll即可
另外需要了解的是,COM組件雖然也是DLL擴展,但它不是PHP擴展,所以把Senc.dll拷貝到php/ext 目錄,然後在PHP.INI里載入是錯誤的,PHP也不認識它
配置完畢後可以測試下,語句為
$word=newCOM("word.application")ordie("UnabletoinstanciateWord");
print"LoadedWord,version{$word->Version} ";
上面語句本機必須安裝了office才可以
openoffice的為:
$obj=newCOM("com.sun.star.ServiceManager")ordie("UnabletoinstanciateWord");
⑵ 求急送50元Q幣或紅包 php調用COM組件 報錯 想把word格式轉成html格式。。。
$word=new COM("word.application") or die("無法啟動COM組件"); //or 前面需要空格
另外,注意com組件功能只支持windows 版本的php
⑶ 如何用PHP生成word文檔
PHP 生成 word 文檔,可以考慮以下兩類辦法:
1. 利用 windows 系統提供的 com組件。
這種方法的原理,是使用 php 的調用 com 組件功能函數,如果系統里安裝過 office 的伺服器,就可以調用 word.application 。
2. 利用PHP將內容寫入doc文件之中。
這種方法,難分為兩種,一種是生成mht格式寫入word,另一種是編寫純 HTML 格式寫入word。這種方法是基於 word 對 html 的良好支持。
⑷ 釋放COM組件php
$sm=new COM("com.sun.star.ServiceManager");
$d=$sm->createInstance("com.sun.star.frame.Desktop");
...
$d->terminate();//關閉
$sm->dispose();//關閉
⑸ php能夠調用C或C++寫的.dll文件嗎 - PHP進階討論
可以我寫過一個調用SAP BO的COM,要調用必須先安裝好COM組件的,在注冊表查出組件名字(如果你不清楚組件名字的話)我把我寫過的函數給你看看
/**
* 載入COM組件
*/
private function createCompanyObject() {
$company = false;
try {
$company = new COM("SapBobsCom.Company");//這樣就可以獲取COM組件了
} catch(Exception $e) {
$this->errorMsg = $e->getMessage();
}
return $company;
}
⑹ 如何用PHP調用自己編寫的COM組件
首先寫ActiveX Dll:
新建一個VB6工程,ActiveX Dll將工程命名為P_test,類名為c_test ,類的文件內容如下:
Option Explicit
Private MyscriptingContext As scriptingContext
Private MyApplication As Application
Private MyRequest As Request Private MyResponse As Response
Private MyServer As Server
Private MySession As Session Public
Sub OnStartPage(PassedscriptingContext As scriptingContext)
Set MyscriptingContext = PassedscriptingContext
Set MyApplication = MyscriptingContext.Application
Set MyRequest = MyscriptingContext.Request
Set MyResponse = MyscriptingContext.Response
Set MyServer = MyscriptingContext.Server
Set MySession = MyscriptingContext.Session
End Sub
Public Sub OnEndPage()
Set MyscriptingContext = Nothing
Set MyApplication = Nothing
Set MyRequest = Nothing
Set MyResponse = Nothing
Set MyServer = Nothing
Set MySession = Nothing
End Sub
Public Function Test_Number(num) As Variant
If num 0 Then Get_Number_Attrib = 1
If num = 0 Then Get_Number_Attrib = 0
End Function
編譯生成p_test.dll文件
注冊
提示符下運行:regsvr32 p_test.dll
編寫php文件,test.php4代碼如下:
<?php
$b=new COM("p_test.c_test");
$a=$b->Test_Number(-454);
echo $a;
?>
可能碰到的問題是,編譯工程時通不過,要將Microsoft Active Server Pages Object Library引用進來,具體實現"Project->References"找到改庫,並勾上 。