首页 php教程 php手册 COM Functions in PHP4 (Windows)--里面有例子来讲WORD文档读写的。

COM Functions in PHP4 (Windows)--里面有例子来讲WORD文档读写的。

Jun 21, 2016 am 09:12 AM
application nbsp quot the word

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:

$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:

$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):

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:

$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 short cut key and select the Objects Editor . 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:

#*********************************************************
# 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}
";

#Another way to get the version using com_get

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

print "Version using Com_get(): $testversion
";

#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.



本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

word自动换行怎么取消 word自动换行怎么取消 Mar 19, 2024 pm 10:16 PM

在word文档中进行编辑内容时可能会自动换行,如果这时候不调整的话,对于我们的编辑会带来很大的影响,让人十分头疼,这是怎么回事呢?其实是标尺的问题,下面小编就介绍word自动换行怎么取消的解决方法,希望能帮助大家!打开Word文档,输入文字后,尝试复制并粘贴时可能会导致文本跳转到新行,这时需调整设置以解决该问题。2.要解决这个问题,我们首先要知道出现这个问题的原因。这时我们单击工具栏下的视图。3.然后再点击下面的“标尺”选项。4.这个时候我们会发现,文档的上方出现了一个标尺,标尺上面有几个锥形标

Word怎么显示标尺以及标尺的操作方法详解! Word怎么显示标尺以及标尺的操作方法详解! Mar 20, 2024 am 10:46 AM

我们在使用Word的时候,为了编辑内容更好美观,我们经常会使用标尺。要知道,在Word中的标尺包括水平标尺和垂直标尺,用于显示和调整文档的页边距、段落缩进、制表符等。那么,Word中的标尺怎么显示出来的呢?下面,我就来教大家设置标尺的显示方法。有需要的同学赶紧收藏起来吧!步骤如下:1、首先,我们需要把word标尺调出来,默认的word文档是不显示word标尺的,我们只需要点击word中的【视图】的按钮。2、然后,我们找到【标尺】的选项,勾选就可以了。这样一来,word标尺就被我们调出来了!是不是

word文档怎么加手写签名 word文档怎么加手写签名 Mar 20, 2024 pm 08:56 PM

Word文档由于功能的强大被大家广泛使用,word里不但可以插入各种格式,比如图片和表格等等,现在为了文件的完整性真实性,好多文件都需要在文档末尾加入手工签名,听起来这么复杂的问题怎么解决呢,今天小编就教大家word文档怎么加手写签名。使用扫描仪、相机或手机对手写签名进行扫描或拍摄,然后通过PS或其他图片编辑软件对图片进行必要的裁剪处理。2.在要插入手写签名的Word文档中选择“插入—图片—来自文件”,选择裁剪好的手写签名。3.鼠标双击手写签名图片(或右击图片选择“设置图片格式”),弹出“设置图

如何为Word设置页边距 如何为Word设置页边距 Mar 19, 2024 pm 10:00 PM

办公软件中Word是我们最常用的软件之一,我们制作的文字文档一般都会用Word进行操作,有些文档按要求还需要提交纸质版,在进行打印之前,一定要把布局设置好,才能呈现出更好的效果。那么问题来了,Word设置页边距的方法是什么呢?我们有具体的课程讲解为大家解决疑惑。1、打开或新建一个word文档,单击菜单栏上的“页面布局”菜单。2、单击“页面设置”选项的“页边距”按钮。3、在列表中选择常用的页边距。4、如果列表中没有合适的页边距,单击“自定义边距”。5、弹出“页面设置”对话框,在“页边距”选项分别输

word中底纹设置在哪 word中底纹设置在哪 Mar 20, 2024 am 08:16 AM

我们平时经常使用word来办公,但是你是否知道word中底纹设置在哪呢?今天我就来跟大家分享具体的操作步骤,小伙伴们快来看一看吧!1.首先,打开word文档,选中一段需要添加底纹的文字段落信息,然后点击工具栏上的【开始】按钮,找到段落区域,点击右侧的下拉按钮,(如下图红色圈出部分所示)。2.点击下拉框按钮之后,在弹出的菜单选项中,点击【边框和底纹】选项,(如下图红色圈出部分所示)。3.在弹出的【边框和底纹】对话框中,点击【底纹】的这个选项,(如下图红色圈出部分所示)。4.在填充的那一栏,选择颜色

word虚线怎么画 word虚线怎么画 Mar 19, 2024 pm 10:25 PM

word是我们办公经常会用到的软件,里边有很多功能,可以便捷我们的操作,例如:大篇文章的话,我们可以使用里边的查找功能,知道全文里边某个字错了,可以直接替换不用一个个去更改了;向上级交文档的时候可以把文档美化的更好看等等操作,下面小编就来给大家分享word虚线怎么画的步骤,大家一起来学习吧!1.首先,我们打开电脑上的word文档,如下图所示:2.然后,在文档里边输入一串文字,如下图红色圈出部分所示:3.接下来,按住【ctrl+A】选中全部文字,如下图红色圈出部分所示:4.点击菜单栏上边的【开始】

Word向下箭头删除的具体操作步骤! Word向下箭头删除的具体操作步骤! Mar 19, 2024 pm 08:50 PM

在日常办公中,如果从网站复制了一段文字,直接粘贴到Word中时,常会看到【向下箭头】,这种【向下箭头】可以通过选中后删除,但是如果这种符号特别多,那么有没有一个快速删除所有箭头的方法呢?那么今天我就来跟大家分享Word向下箭头删除的具体操作步骤!首先,Word中的【向下箭头】实际上代表【手动换行符】。我们可以用【段落标记】符替换所有的【向下箭头】,如下图所示。2.然后,我们选择菜单栏上边的【查找和替换】选项,(如下图红色圈出部分所示)。3.然后,点击【替换】命令,会弹出一个弹框,点击【特殊符号】

word序号如何自动排序 word序号如何自动排序 Mar 20, 2024 pm 09:20 PM

在word里边内容多的时候,会有很多章节,我们不可能一个章节一个的进行编写,其实我们可以使用word序号自动排序,操作简单方法还方便,不知道怎么操作的小伙伴们快来学习一下吧!1.首先,我们在电脑上打开要处理的文档,如下图所示:2.打开文档后,选择需要自动排序的文字,本示例选择【第1章】和【第2章】按住Ctrl键实现选择多个区域,选定后用鼠标点击Word的【开始】菜单,如下图红色圈出部分所示:3.点击【段落】工具栏上面的编号右边的小三角符号,在弹出菜单中点击需要选择的序号类型,如下图红色箭头指向所

See all articles