首頁  >  文章  >  後端開發  >  acronisdiskdirector10 PHP腳本的10個技巧6

acronisdiskdirector10 PHP腳本的10個技巧6

WBOY
WBOY原創
2016-07-29 08:33:21925瀏覽

PHP和COM
如果你是個冒險份子,而且你正在使用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}
";
// 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,把資料傳輸給它,最後再把檔案儲存到使用者的桌面系統內。

以上就介紹了acronisdiskdirector10 PHP腳本的10個技巧6,包括了acronisdiskdirector10方面的內容,希望對PHP教程有興趣的朋友有所幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn