PHP and COM - Striving To Excel (
Page 2 of 9 )
Since COM is a Microsoft invention, it won't surprise you to hear that
PHP's COM extension is only available for the Windows version of PHP. If you're
using *NIX - well, you're outta luck. Shut down your browser and read a book
instead.
If you're still interested, though, pop open your favourite
editor and create a PHP script containing the following lines of code (this
example assumes that you have a properly-installed copy of Microsoft Excel on
your system):
<?php
// create an object instance
$excel = new COM("Excel.Application") or die("Excel could not be
started");
// 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();
$excel = null;
?>
Now, when you run this script through your Web browser, the
following things should happen very fast:
1. Microsoft Excel will start
up automatically.
2. A new workbook will be added.
3. The workbook
will be automatically saved as "C:\Inventory.xls"
4. Microsoft Excel will
automatically shut itself down.
Wondering how this happened? Keep
reading!