PHP and COM
If you are an adventure and you are running PHP on a Windows System Using CGI, ISAPI, or Apache, you can also obtain the COM function of the system. Now, the work of interpreting COM (the Component Object Model of Microsoft) is left to Microsoft and the books with major titles. However, there is nothing wrong with Dot COM. Below is a small piece of common (no puntion, very common) code.
This code snippet uses PHP to start Microsoft Word in the background, open a new file, type some text, save the file, and close the application:
<?
// 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 ...";
?>
Assume that you are running an Intranet Web site that stores data in the Microsoft SQL Server database. Your users need data in Excel format. Then, you can let PHP Execute necessary SQL queries and format the output results. Then, use COM to start Excel, transfer the data to it, and finally store the files in your desktop system.