I have a PHP application running on an IIS server using PHPSpreadSheet. Excel is installed on the server where the website is hosted. My main goal is to insert data from my database into Excel files for clients. It works for some, but not for others. The issue is that the files have contextual formatting that disappears once the file is saved, which seems to be a known problem. So, I tried a different approach. I created a temporary Excel file named ‘data.xlsm’ with a macro that automatically runs when the file is opened to insert the received data into the client’s Excel file.
My problem is that I can’t open the ‘data.xlsm’ file in my PHP code. If I double-click on it or open it with the server’s ‘cmd’, it works fine.
Cmd: "C:/Program Files/Microsoft Office/root/Office16/Excel.exe" C:/www/dunfreshSQ/FICHIERS/Data.xlsm
I tried reloading the file, modifying it, and then saving it with phpSpreadSheet, but nothing happens. I also attempted to execute the command that works with ‘cmd’, but nothing happens:
$command = '"C:/Program Files/Microsoft Office/root/Office16/Excel.exe" C:/www/dunfreshSQ/FICHIERS/Data.xlsm 2>&1';
$output = array();
$returnValue = null;
exec($command, $output, $returnValue);
I saw that you can run a macro using the PHP COM object, but the problem is that I get an error when I do:
$excel = new COM("Excel.application");
It can’t find the class, even though I have ‘php_com_dotnet.dll’ in my ‘ext’ folder and the extension is activated in ‘php.ini’.
HELP!!!”