仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1839|回复: 18
打印 上一主题 下一主题

[学习教程] PHP网页编程之COM Functions in PHP4 (Windows)--里...

[复制链接]
老尸 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-4 00:24:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
因为函数实在是太多了,慢慢的你就会知道,知道有这个函数就可以。window|word   COM Functions in PHP4 (Windows)
Alain M. Samoun
Introduction
The built-in COM functionality of PHP4 is quite attractive for some of us programming in the win32 environment. So far, there is not much documentation on the subject. This short article will explain how to use COM in real PHP4 programming with three examples using MS office 2000 Word and Excel programs and the Adobe Distiller program. The COM technology has been developed by Microsoft for several years, under different names. As far as this article is concerned, the words OLE, OLE Automation, ActiveX and COM are all the same: They designate an encapsulated piece of code (the Object) that performs some functions for a windows application. PHP4 COM connects to the object (Instantiate the object) and uses its methods and properties.
If you want to reproduce the following examples, here is my configuration:
Windows 98 - MS Office 2000
Apache 1.3.9 Windows
PHP4.02 Dev (08-20-00) Running as CGI
COM tags in PHP4
Lets start with the specific information to use the COM functions with PHP4. To instantiate a component, one needs the "new" operator and the "OLE programmatic identifiers" of the object:
<?php

$instance = new COM("$identifier");

?>
Since COM is a reserved class name in PHP4, it passes the object's identifier to the constructor. Now that we have instantiated the component, we can easily reach its methods and properties, using the OOP class. For example:
<?php

$instance->[Object]->[method1]->[method2]->..->[property];

?>
It's that simple!
There are two tag functions for PHP4 COM that are used when the OOP construct doesn't work. (In the case of PHP syntax problems, with the names and values of properties with invalid characters, like dot or parenthesis):
<?php

bool com_set(class com_object, string property name, string property_value);

mixed com_get(class com_object, string property_name);

?>
Finally, PHP4 also supports DCOM to create an instance of an object on a remote computer:
<?php

$Instance = new COM(string "Component name", string "remote_server_address");

?>
Note: there is a DCOM directive to set in the PHP configuration. PHP developers may add DCOM support for Unix in the future. That's all, there are no other functions to remember!
Identifiers, methods and properties.
identifiers are strings like:
    For MS Word:   "Word.Application" or "Word.Application.9"
    MS Excel:      "Excel.Application" or "Excel.Sheet"
    ADOBE Acrobat: "Exch.application" or "PdfDistiller.PdfDistiller"
As the last identifier name indicates, it is not always easy to know the right name for the object. If you do not have access to a VBA doc, you can look at the windows registry (Start - Run regedit) and look in the HKEY_CLASSES_ROOT folder: Scan down until the end of the extensions list, you will then reach the Application names. The COM Identifiers available in your machine, are the folders with the CLSID subfolders.
The application program should document its COM methods and properties. In the case of Office 2000, start the application, then open the visual basic editor with the <ALT+F11> short cut key and select the Objects Editor <F2>. Enter a name of method or properties for the application's library. Then, select a class or member and right click on the member name in the next window below. You will get the description for the class or member by selecting help. You can also consult MSDN. An example for Excel is: http://msdn.microsoft.com/library/officedev/off2000/xltocobjectmodelapplication.htm
Using PHP4 COM functions with MS Word
Now, we have all we need to start with the first code example:
<?php

#*********************************************************
# This example, slightly modified from the Zend site,
#  will open an instance of word with a new
# document with the name "Useless test.doc" and the line:
# "This is a test2..." typed inside.
#*********************************************************

#Instantiate the Word component.

$word = new COM("word.application") or die("Unable to instantiate Word");

#Get and print its version

print "Loaded Word, version {$word->Version}<BR>";

#Another way to get the version using com_get

$testversion = com_get($word->application,version);

print "Version using Com_get(): $testversion <BR>";

#Make it visible in a window

$word->Visible = 1;

#Open a new document

$word->Documents->Add();

#Write something

$word->Selection->TypeText("This is a test...");

#Now save the document

$word->Documents[1]->SaveAs("Useless test.doc");

#Comment next line if you want to see the word document,
#then close word manually

$word->Quit();
#Comment if you want to see the word document, then close

?>
If you study this example for a few minutes using the OLE documentation that comes with Word, you will learn practically all you need to write your own program.
  我先解释一下我的学习思路。
若天明 该用户已被删除
沙发
发表于 2015-2-4 13:00:26 | 只看该作者
首推的搜索引擎当然是Google大神,其次我比较喜欢 百度知道。不过搜出来的结果往往都是 大家copy来copy去的,运气的的概率很大。
变相怪杰 该用户已被删除
板凳
发表于 2015-2-7 12:52:42 | 只看该作者
我还是推荐用firefox ,配上firebug 插件调试js能省下不受时间。谷歌的浏览器最好也不少用,因为谷歌的大侠们实在是太天才啦,把一些原来的js代码加了一些特效。
兰色精灵 该用户已被删除
地板
发表于 2015-2-7 14:37:28 | 只看该作者
遇到出错的时候,我经常把错误信息直接复制到 google的搜索栏,一般情况都是能搜到结果的,不过有时候会搜出来一大片英文的出来,这时候就得过滤一下,吧中文的弄出来,挨着式方法。
若相依 该用户已被删除
5#
发表于 2015-2-11 09:06:06 | 只看该作者
环境搭建好,当你看见你的浏览器输出“it works\\\\\\\"时你一定是喜悦的。在你解决问题的时候,我强烈建议多读php手册。
飘灵儿 该用户已被删除
6#
发表于 2015-3-2 08:02:28 | 只看该作者
当留言板完成的时候,下步可以把做1个单人的blog程序,做为目标,
7#
发表于 2015-3-6 20:20:19 | 只看该作者
本文当是我的笔记啦,遇到的问题随时填充
小妖女 该用户已被删除
8#
发表于 2015-3-8 21:13:28 | 只看该作者
写js我最烦的就是 ie 和 firefox下同样的代码 结果显示的结果千差万别,还是就是最好不要用遨游去调试,因为有时候遨游是禁用js的,有可能代码是争取结果被遨游折腾的认为是代码写错。
山那边是海 该用户已被删除
9#
发表于 2015-3-11 18:25:34 | 只看该作者
要进行开发,搭建环境是首先需要做的事,windows下面我习惯把环境那个安装在C盘下面,因为我配的环境经常出现诡异事件,什么事都没做环境有的时候就不能用啦。
莫相离 该用户已被删除
10#
发表于 2015-3-12 07:58:10 | 只看该作者
使用zendstdio 写代码的的时候,把tab 的缩进设置成4个空格是很有必要的
第二个灵魂 该用户已被删除
11#
发表于 2015-3-17 12:09:40 | 只看该作者
说点我烦的低级错误吧,曾经有次插入mysql的时间 弄了300年结果老报错,其实mysql的时间是有限制的,大概是到203X年  具体的记不清啦,囧。
爱飞 该用户已被删除
12#
发表于 2015-3-18 11:13:16 | 只看该作者
首先我是坚决反对新手上来就用框架的,因为对底层的东西一点都不了解,造成知识上的真空,会对以后的发展不利。我的观点上手了解下框架就好,代码还是手写。当然啦如果是位别的编程语言的高手的话,这个就另当别论啦。
再现理想 该用户已被删除
13#
发表于 2015-3-24 06:13:17 | 只看该作者
其实也不算什么什么心得,在各位大侠算是小巫见大巫了吧,望大家不要见笑,若其中有错误的地方请各位大虾斧正。
深爱那片海 该用户已被删除
14#
发表于 2015-3-26 07:13:11 | 只看该作者
小鸟是第一次发帖(我习惯潜水的(*^__^*) 嘻嘻……),有错误之处还请大家批评指正,另外,前些日子听人说有高手能用php写驱动程序,真是学无止境,人外有人,天外有天。
只想知道 该用户已被删除
15#
发表于 2015-3-30 23:40:29 | 只看该作者
为了以后维护的方便最好是代码上都加上注释,“予人方便,自己方便”。此外开发文档什么的最好都弄齐全。我觉得这是程序员必备的素质。虽然会消耗点很多的时间。但是确实是非常有必要的。
谁可相欹 该用户已被删除
16#
发表于 2015-4-1 07:43:23 | 只看该作者
要进行开发,搭建环境是首先需要做的事,windows下面我习惯把环境那个安装在C盘下面,因为我配的环境经常出现诡异事件,什么事都没做环境有的时候就不能用啦。
蒙在股里 该用户已被删除
17#
发表于 2015-4-10 03:43:15 | 只看该作者
其实也不算什么什么心得,在各位大侠算是小巫见大巫了吧,望大家不要见笑,若其中有错误的地方请各位大虾斧正。
金色的骷髅 该用户已被删除
18#
发表于 2015-4-21 02:20:33 | 只看该作者
首推的搜索引擎当然是Google大神,其次我比较喜欢 百度知道。不过搜出来的结果往往都是 大家copy来copy去的,运气的的概率很大。
飘飘悠悠 该用户已被删除
19#
发表于 2015-4-21 21:10:53 | 只看该作者
写的比较杂,因为我也是个新手,不当至于大家多多指正。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-11-16 20:56

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表