10 tips for PHP scripts (6)

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.