PHP COM (OLE) Object connecting to MS Excel

2019-08-29 05:40发布

My setup: IIS 7.5, PHP 5.4, Windows 7

I've trying to create a COM Object through PHP but I continue to get access denied. I've also followed a handful of tutorials on how to "grant access" to the ISUR to create the object but to no avail. I read the installation portion relevant to COM interfacing that says:

As of PHP 5.3.15 / 5.4.5, this extension requires php_com_dotnet.dll to be enabled inside of php.ini in order to use these functions. Previous versions of PHP enabled these extensions by default.

You are responsible for installing support for the various COM objects that you intend to use (such as MS Word); we don't and can't bundle all of those with PHP.

I've enabled the php_com_dotnet.dll file within the ini file but I still can't seem to create the COM object for Excel. Then if you read the second paragraph it says that you have to install support for the various COM objects you intend to use but doesn't specify how to go about doing that.

Question: How do I install support for the MS Excel COM object?

Any help would be appreciated. I've researched this issue but haven't found very much documentation out there.

标签: php excel iis com
1条回答
Anthone
2楼-- · 2019-08-29 05:43

Don't do this. You're in for a world of pain trying to launch Excel in a web application, especially from PHP.

Microsoft Office apps such as Word and Excel are not designed for server side use. When you try to instantiate an Excel "COM object" you're spinning up a full instance of Excel as a separate process. That is hugely expensive and will never scale. Not only that, to add to your woes, if for whatever reason your script can't release and shut down Excel you'll end up with tens or possibly hundreds of orphaned Excel processes hanging around in memory.

Try something like: https://github.com/PHPOffice/PHPExcel if you need to read and write Excel compatible spreadsheets.

查看更多
登录 后发表回答