此代码片断适用于在Windows的Web服务器上用PHP创建MS Word 文件。
The following code can be used to create .doc document with PHP on Windows Web server. It makes use of COM component, which is only available on Windows server.
<?php
/**
* Create a new COM object model
*/
$word = new COM("word.application")
or die("Unable to instanciate Word");
$word->Visible = 1;
$word->Documents->Add();
// Write content
$word->Selection->TypeText("This is a test...");
// Save as .doc document
$word->Documents[1]->SaveAs("Useless_test.doc");
// Release the object
$word->Quit();
$word = null;
?>