当前位置: 首页 > 图文教程 > 网络编程 > PHP > PHP脚本的8个技巧(6)

PHP
PHP 执行系统外部命令 system() exec() passthru()
最新的php 文件上传模型,支持多文件上传
php 静态页面中显示动态内容
数据库查询记录php 多行多列显示
谈PHP生成静态页面分析 模板+缓存+写文件
PHP 各种排序算法实现代码
PHP nl2br函数 将换行字符转成 <br>
php 分页原理详解
Discuz 模板语句分析及知识技巧
php win下Socket方式发邮件类
怎样去阅读一份php源代码
建站常用13种PHP开源CMS比较
php xml留言板 xml存储数据的简单例子
PHP 开源AJAX框架14种
PHP 替换模板变量实现步骤
PHP has encountered an Access Violation at 7C94BD02解决方法
php 正则匹配函数体
php 文件夹删除、php清除缓存程序
php download.php实现代码 跳转到下载文件(response.redirect)
PHP类(Class)入门教程

PHP脚本的8个技巧(6)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 178 ::
收藏到网摘: n/a

PHP和COM

如果你是一名冒险份子,而且你正在使用CGI、ISAPI或Apache模块版本的Windows系统上运行着PHP,那么你也可以获得系统的COM功能。现在,解释COM(微软的组件对象模型)的工作留给了微软和那些大部头的图书来完成。然而,知道点COM也没什么错,下面有一个普通的(没有双关语,针对很普通)代码小片断。

这代码小片断使用PHP在后台启动MicrosoftWord、打开一个新文件、键入一些文本、保存该文件然后关闭应用程序:

<?
//createareferencetoanewCOMcomponent(Word)
$word=newCOM("word.application")ordie("Can'tstartWord!");

//printtheversionofWordthat'snowinuse
echo"LoadingWord,v.{$word->Version}<br>";

//setthevisibilityoftheapplicationto0(false)
//toopentheapplicationintheforefront,use1(true)
$word->Visible=0;

//createanewdocumentinWord
$word->Documents->Add();

//addtexttothenewdocument
$word->Selection->TypeText("Testing1-2-3...");

//savethedocumentintheWindowstempdirectory
$word->Documents[1]->SaveAs("/Windows/temp/comtest.doc");

//closetheconnectiontotheCOMcomponent
$word->Quit();

//printanothermessagetothescreen
echo"Checkforthefile...";
?>

假设你正在运行一个内联网Web站点,该站点把数据存放在MicrosoftSQLServer数据库内,你的用户需要Excel格式的数据。那么,你可以让PHP执行必要的SQL查询并且格式化输出结果,然后使用COM启动Excel,把数据传输给它,最后再把文件存储到用户的桌面系统内。