nt05的记事本

我好笨
  首页  :: 管理

php调用COM

Posted on 2008-06-04 16:46  nt05  阅读(299)  评论(0编辑  收藏  举报

这里是一个PHP用COM操作windows下word的过程

PHP代码
  1. <?    
  2. // create a reference to a new COM component (Word)   
  3. $word = new COM("word.application") or die("Can't start Word!");    
  4.   
  5. // print the version of Word that's now in use   
  6. echo "Loading Word, v. {$word->Version}<br>";    
  7.   
  8. // set the visibility of the application to 0 (false)    
  9. // to open the application in the forefront, use 1 (true)   
  10. $word->Visible = 0;    
  11.   
  12. // create a new document in Word   
  13. $word->Documents->Add();    
  14.   
  15. // add text to the new document   
  16. $word->Selection->TypeText("Testing 1-2-3...");    
  17.   
  18. //save the document in the Windows temp directory   
  19. $word->Documents[1]->SaveAs("/Windows/temp/comtest.doc");    
  20.   
  21. // close the connection to the COM component   
  22. $word->Quit();    
  23.   
  24. // print another message to the screen   
  25. echo "Check for the file...";    
  26. ?>