Discuz教程网

PHP脚本的8个技巧之PHP和COM

[复制链接]
authicon 09927306 发表于 2010-12-5 11:31:58 | 显示全部楼层 |阅读模式
  如果你是一名冒险份子,而且你正在使用CGI、ISAPI或Apache模块版本的Windows系统上运行着PHP,那么你也可以获得系统的COM功能。现在,解释COM(微软的组件对象模型)的工作留给了微软和那些大部头的图书来完成。然而,知道点COM也没什么错,下面有一个普通的(没有双关语,针对很普通)代码小片断。
这代码小片断使用PHP在后台启动Microsoft Word、打开一个新文件、键入一些文本、保存该文件然后关闭应用程序:
  1. <?
  2. // create a reference to a new COM component (Word)
  3. $word = new COM("word.application") or die("Can't start Word!");
  4. // print the version of Word that's now in use
  5. echo "Loading Word, v. {$word->Version}<br>";
  6. // set the visibility of the application to 0 (false)
  7. // to open the application in the forefront, use 1 (true)
  8. $word->Visible = 0;
  9. // create a new document in Word
  10. $word->Documents->Add();
  11. // add text to the new document
  12. $word->Selection->TypeText("Testing 1-2-3...");
  13. //save the document in the Windows temp directory
  14. $word->Documents[1]->SaveAs("/Windows/temp/comtest.doc");
  15. // close the connection to the COM component
  16. $word->Quit();
  17. // print another message to the screen
  18. echo "Check for the file...";
  19. ?>
复制代码

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



上一篇:PHP脚本的8个技巧之采用PHP的用户认证
下一篇:PHP脚本的8个技巧之PHP和Java
authicon nancybingling 发表于 2011-5-9 08:59:31 | 显示全部楼层
支持!好东西,拿走了!
authicon YY大兔子 发表于 2011-5-10 10:59:47 | 显示全部楼层
好东西要顶的。
authicon 暗夜的烟火 发表于 2011-6-18 19:00:15 | 显示全部楼层
支持!好东西,拿走了!
authicon nancybingling 发表于 2011-6-22 03:00:27 | 显示全部楼层
前来看看那
authicon YNKAZUKI 发表于 2011-6-23 12:59:48 | 显示全部楼层
支持楼主,顶一下
authicon 丁加丁 发表于 2011-6-25 10:59:48 | 显示全部楼层
哈哈,支持了
authicon icenna 发表于 2011-8-9 15:47:35 | 显示全部楼层
哈哈  收了你
authicon YNKAZUKI 发表于 2011-8-10 10:32:01 | 显示全部楼层
好辛苦才找到啊
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 09:37

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

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