PHP
  Home arrow PHP arrow Page 3 - PHP and COM
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

PHP and COM
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2002-04-23

    Table of Contents:
  • PHP and COM
  • Striving To Excel
  • The Number Game
  • Export Potential
  • Keeping It Simple
  • Access-ing The Web
  • All For One, And One For All
  • New Coins For Old
  • Link Zone

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    PHP and COM - The Number Game


    (Page 3 of 9 )

    PHP's COM extension makes it easy to access and manipulate COM objects that have been registered on your system. One of these objects is the Excel.Application object, which exposes a number of methods and properties that can be creatively used by an imaginative developer.

    The first step to using a COM object in your PHP script involves creating an instance of the COM class; to quote the PHP manual, this class provides you with "...a framework to integrate COM into your PHP scripts".

    <?php // create an object instance $excel = new COM("Excel.Application") or die("Excel could not be started"); ?>
    The argument passed to the class constructor is the name of the component to be used. In this case, since I want an instance of Microsoft Excel, I've used the Excel.Application object (more information on this object can be obtained at http://msdn.microsoft.com/library/en-us/modcore/html/deovrworkingwithmicrosoftexcelobjects.asp)

    By default, PHP assumes that the component is available on the local server. In the event that you would like the component to be fetched from a remote DCOM server, the server name can be specified as a second, optional argument to the constructor. Note, however, that in order for this to work, the PHP configuration variable

    com.allow_dcom = true
    must be set, either in the PHP configuration file or via the ini_set() function call.

    Once an object instance has been created, object methods and properties can be accessed using standard OO conventions.

    <?php // pop open the Excel application $excel->Visible = 1; // turn off alerts $excel->DisplayAlerts = 0; // add a workbook $excel->Workbooks->Add(); // save $excel->Workbooks[1]->SaveAs("C:\\Inventory.xls"); // close the application $excel->Quit(); ?>
    Since the Excel.Application object exposes a number of different methods and properties, you can use it to create workbooks, add sheets to the workbook, add or delete content to the cells of the worksheet, apply formulae to the cells, save the workbook to the disk...in fact, everything that you would be able to do with the application itself.

    Keeping this in mind, the example above is fairly simplistic - all it does is create an Excel workbook and save it as a file - but it nevertheless demonstrates how easy it is to do something that, in theory at least, sounds very difficult ("hey Matt, any idea how to create an Excel spreadsheet in Windows using just PHP?").

    More PHP Articles
    More By Harish Kamath, (c) Melonfire


     

       

    PHP ARTICLES

    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter
    - Building Your Own System Tray Application Us...
    - Structuring Your Projects for Web Applicatio...
    - Inserting, Updating and Deleting Database Ro...
    - Building Your Own Desktop Notepad Applicatio...
    - Web Application Security Overview
    - Working with the Active Record Class in Code...
    - Generate PDF Documents with PHP on the Windo...
    - Sending Email with PHP Networking
    - Performing Strict Validation with the Code I...
    - The preg_replace_callback() function in PHP





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT