none
How to launch unattended Excel.exe from a web page

    Question

  • Suppose I have a Windows server with Excel or indeed Office installed, 2010 or 2013.

    I would like that to offer a web page with a script for a user to upload a file - that's standard enough I imagine.

    Then I want the script to launch Excel with a macro-enabled XLSM workbook, pass it that filename as a parameter, and it does its thing and quits, with no UI required. It's simply a processing mechanism. That's because I know VBA and Excel and already have that processing written there and don't want to learn .Net to rewrite the application completely. The presence of thousands of lines of VBA is why Office 365 is no help because that does not support VBA.

    Yes, I know MS deprecate Office automation on servers because at some point some error will produce an error message and the process hangs, but I'm prepared to live with that for low volume - this might be one run a day, maybe a few.

    So, does anyone have a write up or web page or a book somewhere that describes how to do this?

    Here is as far as I got for a test: I set up IIS7 on my PC, got localhost working, tried a simple ASP script but even after allowing IIS_IUSERS to execute Excel.exe I'm still getting a COM error. There seem to be a number of hacks involved, see these threads. So I am hoping someone has documented a method of doing this.

    http://forums.asp.net/t/1303594.aspx/1

    http://social.msdn.microsoft.com/Forums/en-US/b81a3c4e-62db-488b-af06-44421818ef91/excel-2007-automation-on-top-of-a-windows-server-2008-


    <%

    dim xl as object

    xl=Server.CreateObject("Excel.**Application")

    response.write( xl.name )

    xl.quit

    %>



    Server Error in '/' Application.

    Retrieving the COM class factory for component with CLSID

    {00024500-0000-0000-C000-**000000000046} failed due to the following

    error: 80070005.

    [...]To grant ASP.NET access to a file, right-click the file in

    Explorer, choose "Properties" and select the Security tab. Click "Add"

    to add the appropriate user or group. Highlight the ASP.NET account,

    and check the boxes for the desired access.

    Saturday, September 07, 2013 6:36 PM

Answers

  • Hi,

    I reproduce the issue by creating a ASP.Net Web Application and deploy the project on IIS 8 (Windows 8).
    Below is my test code :

    protected void Page_Load(object sender, EventArgs e)
            {
                Microsoft.Office.Interop.Excel.Application oExcel = new Microsoft.Office.Interop.Excel.Application();
                Response.Write(oExcel.Name);
            }
    

    To work around, we can grant the access rights to Application Pool Identities follow steps below:
    1. Run dcomcnfg from the command prompt.
    2. Right click Console Root>Component Services>Computers>My computer>DCOM Config>Microsoft Excel Application and add account like finger below:

    Change the identity of Application Pool from ApplicationPoolIdentity to LocalSystem, the issue was resolved:


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by sysmod Wednesday, September 11, 2013 4:28 PM
    Tuesday, September 10, 2013 1:30 AM
    Moderator

All replies

  • Hi,

    I reproduce the issue by creating a ASP.Net Web Application and deploy the project on IIS 8 (Windows 8).
    Below is my test code :

    protected void Page_Load(object sender, EventArgs e)
            {
                Microsoft.Office.Interop.Excel.Application oExcel = new Microsoft.Office.Interop.Excel.Application();
                Response.Write(oExcel.Name);
            }
    

    To work around, we can grant the access rights to Application Pool Identities follow steps below:
    1. Run dcomcnfg from the command prompt.
    2. Right click Console Root>Component Services>Computers>My computer>DCOM Config>Microsoft Excel Application and add account like finger below:

    Change the identity of Application Pool from ApplicationPoolIdentity to LocalSystem, the issue was resolved:


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by sysmod Wednesday, September 11, 2013 4:28 PM
    Tuesday, September 10, 2013 1:30 AM
    Moderator
  • Thank you!

    I can see Excel appearing in the Task Manager.

    I now get an error at

    xl.workbooks.open("F:\DOCS\Excel\cmdline.xlsm")

    but I can work on that - probably need all 19 parameters or something.

    Anyway, yours was the answer!

    Patrick

    Wednesday, September 11, 2013 4:30 PM