先到PHP.INI中打开COM选项,com.allow_dcom = true
配置方法为:只需在扩展列表里添加extension=php_com_dotnet.dll即可
另外需要了解的是,COM组件虽然也是DLL扩展,但它不是PHP扩展,所以把Senc.dll拷贝到php/ext 目录,然后在PHP.INI里加载是错误的,PHP也不认识它
配置完毕后可以测试下,语句为
$word?=?new?COM("word.application")?or?die("Unable?to?instanciate?Word");
print?"Loaded?Word,?version?{$word-Version}\n";
上面语句本机必须安装了office才可以
openoffice的为:
$obj?=?new?COM("com.sun.star.ServiceManager")?or?die("Unable?to?instanciate?Word");
COM组件是通用的,如果你想用调用COM组件来操作EXCEL文档,建议可以参考的工具和资料如下:
① office (excel)VBA帮助文档,VBA中包含对象、属性、方法的说明.
oleview软件
首先我假定你当前的URL是localhost/show.php 其次你数据库的需要一个主键 PRIMARY KEY
首先写ActiveX Dll:
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
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文件
注册
php
$b=new COM("p_test.c_test");
echo $a;
可能碰到的问题是,编译工程时通不过,要将Microsoft Active Server Pages Object Library引用进来,具体实现"Project-References"找到改库,并勾上 .
以下一个php调用COM访问excel的示例:
//指定页面编码,防止出现中文乱码的情形
//启动Excel
$ms_excel = new COM("excel.application") or die("不能打开Excel应用程序");
//打开excel文件
$ms_excel-Application-WorkBooks-Open( 'e:\test\test.xls') or die("不能打开工作簿");
//保存工作簿
if(!$ms_excel-ActiveWorkBook-Saved)
{
$ms_excel-ActiveWorkBook-save();
}
//关闭工作簿
$ms_excel-Quit();
//清空对象
$ms_excel = null;
以上就是土嘎嘎小编为大家整理的phpcom相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!