Page 1 of 1

COM with PHP

Posted: Tue Jun 11, 2002 10:33 am
by gastonlm
I'm executing the following code and I recive an error. I don't know if I should have something installed in the server or in my machine. The code is the following and is for creating an excel file:

$exapp = new COM("excel.application") or Die ("Did not connect");
$exapp->Visible = true;
$workbook = $exapp->workbooks->Add();
$worksheet = $workbook->Worksheets(1);
$worksheet->activate;
$cell = $worksheet->Cells(1,1);
$cell->value = "Name";
$cell = $worksheet->Cells(1,2);
$cell->value = "Salary";
$cell = $worksheet->Cells(1,3);
$cell->value = "Time of Employment";
$worksheet->SaveAs("c:\\emp_reports-salary.xls");
$exapp->quit();

I recive the error:

Warning: Invalid ProgID, GUID string, or Moniker: Invalid syntax in C:\Web\admin\consultas\hoteles.php on line 331
Did not connect

Is the first time I'm trying to use a com object, so I don't know exactly how it works.
Can anybody help me??

Posted: Tue Jun 11, 2002 12:07 pm
by Zmodem
PHP does have COM support. But I'm sure it's pretty buggy. I believe it is also fairly new, and not very mature.

If you want to do a lot of stuff like that, you might try looking into ASP, which is better suited for complicated COM operations.

Just a suggestion....

Posted: Tue Jun 11, 2002 1:47 pm
by volka
use regedit.exe to take a look into your registry settings.
Search for 'Excel.Application' (should be 'HKEY_CLASSES_ROOT\Excel.Application'). If it isn't there you have to install Excel first ;)
If you find it change new COM("excel.application") to new COM("Excel.Application"). May be it's case sensitive.

Posted: Tue Jun 11, 2002 4:17 pm
by gastonlm
I've solved.