10 Tips for PHP scripts (from ZDNet)--php and COM

Source: Internet
Author: User
Tags format microsoft sql server sql object model php and
Tricks | scripting PHP and COM

If you're an adventurer and you're running PHP on a CGI, ISAPI, or Apache version of a Windows system, you can also get the COM functionality of the system. Now, the job of interpreting COM (Microsoft's Component Object model) has been left to Microsoft and the voluminous books to complete. However, there is nothing wrong with dot com, and below is a trivial piece of code (no pun intended for very common).

This little snippet of code uses PHP to start Microsoft Word in the background, open a new file, type some text, save the file, and then 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?
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 ...";
?>

Let's say you're running an intranet Web site that stores data in a Microsoft SQL Server database, and your users need data in Excel format. Then you can have PHP execute the necessary SQL queries and format the output, then use COM to start Excel, transfer the data to it, and then store the file in the user's 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.