OLE AUTOMATION WITH PHP or PHP-CLI?
I read here http://www.daniweb.com/code/snippet217293.html# .
What needs to be activated in PHP.Ini or anywhere else to make this work? Are there examples with Excel?
+2
a source to share
2 answers
If you are using php for Windows it will be installed by default. There are several options you can set. I do not believe they are needed:
http://www.php.net/manual/en/com.configuration.php
As for an example of working with excel? Here is a small snippet I found for pulling a value from an Excel spreadsheet:
<?PHP
$filename = "c:/spreadhseet/test.xls";
$sheet1 = 1;
$sheet2 = "sheet2";
$excel_app = new COM("Excel.application") or Die ("Did not connect");
print "Application name: {$excel_app->Application->value}\n" ;
print "Loaded version: {$excel_app->Application->version}\n";
$Workbook = $excel_app->Workbooks->Open("$filename") or Die("Did not open $filename $Workbook");
$Worksheet = $Workbook->Worksheets($sheet1);
$Worksheet->activate;
$excel_cell = $Worksheet->Range("C4");
$excel_cell->activate;
$excel_result = $excel_cell->value;
print "$excel_result\n";
$Worksheet = $Workbook->Worksheets($sheet2);
$Worksheet->activate;
$excel_cell = $Worksheet->Range("C4");
$excel_cell->activate;
$excel_result = $excel_cell->value;
print "$excel_result\n";
#To close all instances of excel:
$Workbook->Close;
unset($Worksheet);
unset($Workbook);
$excel_app->Workbooks->Close();
$excel_app->Quit();
unset($excel_app);
?>
+3
a source to share