we are having issues saving excel sheets in PHP.
Minimalistic code:
// R: is a Ramdisk $filename = 'R:\sheets\ExcelFile_123.xlsx'; $application = new COM("Excel.Application", null, CP_UTF8); $workbook = $application->Workbooks->Open($filename); $workbook->save();
The call to save will throw a com_exception with message “Source: Microsoft Excel Description: Das Dokument wurde nicht gespeichert.” (German for “The document was not saved.”)
When any worksheet of the workbook has been opened and i am trying to save the worksheet again i get another com_exception with message “Source: Microsoft Excel Description: Zugriff auf ‘ExcelFile_123.xlsx’ verweigert.” (German for “Access to ‘ExcelFile_123.xlsx’ denied.”)
I checked following things:
- The Excel file does not have any Links to other sheets.
- The Excel file is not write protected.
- The file can be written to disk by PHP (PHP has write access to the file and folder)
- The Excel file is not shared.
- No other Excel Application is open.
I toggled every setting of the ones mentioned above and even tried https://support.microsoft.com/en-us/help/2589410/access-denied-error-message-when-you-save-a-workbook-to-a-unc-share-in
Solutions that are not suitable:
- Using another PHP Excel Library (The Excel files heavily depend on calculations and conditions)
- Using Microsoft Grap
- Using Microsoft Office 365
- Using Google SPreadsheet
Question: Why can’t i save the excel file, even though i have write access?
System information
- Server: Windows 2012 R2
- Webserver: Apache 2.4
- PHP: 5.5.14 (I am aware of the security implications)
PHP com_dotnet extension:
com_dotnet COM support enabled DCOM support disabled .Net support enabled Directive Local Value Master Value com.allow_dcom 0 0 com.autoregister_casesensitive 1 1 com.autoregister_typelib 0 0 com.autoregister_verbose 0 0 com.code_page no value no value com.typelib_file no value no value
Advertisement
Answer
It can be an issue with user profile under which your PHP application is running. Please check article on server-side office automation of office products (it has common problems listed). To see if the problem is actually the account, I would try to change the account under Apache (PHP) is running to your account (or simply start Apache command line to see if it fixes the problem).
https://support.microsoft.com/en-us/help/257757/considerations-for-server-side-automation-of-office
https://theether.net/download/Microsoft/kb/288367.html
BTW, there are (paid) alternatives as well that can do calculations and run server-side.