0

I call a power shell script from php with shell_exec

Power shell script opens an excel workbook and runs a macro:

$excel = new-object -comobject excel.application
$excelFiles = Get-ChildItem -Path e:\dt\surgicare\something.xlsm
$app = $excel.Application
$workbook = $app.workbooks.open($excelfiles)
$app.Visible = $false
$workbook.Activate()
$app.Run("surgicare_frissites")
$workbook.close($false)
$excel.quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($app)
Remove-Variable app
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)
Remove-Variable excel

It can run ps script, but it returns error. I can read in "wamp/logs/php_error.log" that Microsoft Excel cannot open something.xlsm.

The same error is in "wamp/logs/apache_error.log"

If I run power-shell script manually it works fine, there is no error, macro does what it has to do.

Any idea? What did I miss?

1 Answers1

0

Win7x64, PHP 8.0 (XAMPP), Excel 16, in PHP ini add extension=php_com_dotnet.dll

<?php
// starting Excel
$objExcel = new com("excel.application") or die("Unable to instantiate objExcel");
echo "Loaded objExcel, version {$objExcel->Version}\n";

//closing objExcel
$objExcel->Quit();

//free the object
$objExcel = null;
?>

And I see in Firefox: Loaded objExcel, version 16.0