动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   PHP → 阅读文章

 PHP和COM

作者来源: 
阅读 1238 人次 , 2006-3-29 4:10:00 


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

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

<?
// create a reference to a new com component (word)
$word = new com("word.application") or die("can't start word!");

// print the version of word that's now in use
echo "loading word, v. {$word->version}<br>";

// set the visibility of the application to 0 (false)
// to open the application in the forefront, use 1 (true)
$word->visible = 0;

// create a new document in word
$word->documents->add();

// add text to the new document
$word->selection->typetext("testing 1-2-3...");

//save the document in the windows temp directory
$word->documents[1]->saveas("/windows/temp/comtest.doc");

// close the connection to the com component
$word->quit();

// print another message to the screen
echo "check for the file...";
?>

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

 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:PHP和Java
· 下一篇:PHP动态创建图象
· 在PHP中使用XML
· Session 函数库
· 用PHP调用Oracle存储过程
· 分页显示详解
· 通过ODBC连接的SQL SERVER实例


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077