Mukesh Sahani
Mukesh Sahani

Reputation: 1

Use of COM Class in PHP

I am using following code to access excel file in php.

        $excel = new COM("Excel.application",,) or die ("ERROR: Unable to instantaniate   COM!\r\n");

// DATA RETRIEVAL
$Workbook = $excel->Workbooks->Open($file) or die("ERROR: Unable to open " . $file . "!\r\n");
$Worksheet = $Workbook->Worksheets($sheet);
$Worksheet->Activate;

The above code working on local machine but when I try to execute this code on any web server then It's not working. Can Someone help me Where is the problem in this code.

Upvotes: 0

Views: 1632

Answers (2)

davidbcn
davidbcn

Reputation: 1

You need Excel to be installed on your servers + the php process needs the correct permissions to be able to access the COM application.

We've had lot's of trouble with Office Interop in the past and I advise against it. If anything happens to your process the Excel instances are kept open on the server and these instances take up a lot of RAM.

You are better off using libraries that leverage the OpenXML specification, such as Spreadsheetlight:

http://spreadsheetlight.com/

You can use it from PHP, there is an example here:

http://www.drupalonwindows.com/en/blog/importing-excel-data-php-openxml-and-spreadsheetlight-drupal-example

Upvotes: 0

RageZ
RageZ

Reputation: 27323

I advice you to use PHPExcel instead of COM.

COM is really slow and work only on windows, plus you have to install office on a server which is a waste of a license.

Upvotes: 4

Related Questions