none
Excel Automation through windows service written in C# fails in Office 365 installed machines RRS feed

  • Question

  • I am working with Windows Service written in C#. Through this windows service I am automating Excel in programmatic way.

    Excel.Application excel = Excel.Application();

    This code was working fine with all versions of Excel (2003,2007,2010,2013). Recently I have installed Office 365 in my machine. Suddenly I am getting below exception when I automate the Excel using above call.

    Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

    Can anyone let me know, is there any special consideration should be taken when automate the Office 365 Excel via Windows Service

    Monday, September 21, 2015 9:52 AM

Answers

  • Hello,

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article. 

    You may consider using the Open SDK instead, see Welcome to the Open XML SDK 2.5 for Office for more information. Or just use any third-party components designed for the server-side execution.

    Monday, September 21, 2015 10:16 AM
  • Hi,

    >> However I have to do the excel automation because the Excel File I am opening via the service is a document level customization and doing various operations inside the customization. In order to do this I have to somehow automate the excel in the hidden mode and add the books to the application.<<

    The issue is not relative to he hidden mode. As Eugene stated that Microsoft doesn't support Office automation on the server side. 

    Based on my understanding, we can use Open XML SDK to manipulate the Office documents as a workaround. Or we can try develop an console application to automate the Office application instead of in the Windows service.

    Hope it is helpful.

    Regards & Fei  


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, September 28, 2015 8:07 AM
    Moderator

All replies

  • Hello,

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article. 

    You may consider using the Open SDK instead, see Welcome to the Open XML SDK 2.5 for Office for more information. Or just use any third-party components designed for the server-side execution.

    Monday, September 21, 2015 10:16 AM
  • I agree there are security issues when automating Excel from a service. However I have to do the excel automation because the Excel File I am opening via the service is a document level customization and doing various operations inside the customization. In order to do this I have to somehow automate the excel in the hidden mode and add the books to the application. Is there any other ways to automate the Excel in hidden Mode? 
    Friday, September 25, 2015 11:41 AM
  • Hi,

    >> However I have to do the excel automation because the Excel File I am opening via the service is a document level customization and doing various operations inside the customization. In order to do this I have to somehow automate the excel in the hidden mode and add the books to the application.<<

    The issue is not relative to he hidden mode. As Eugene stated that Microsoft doesn't support Office automation on the server side. 

    Based on my understanding, we can use Open XML SDK to manipulate the Office documents as a workaround. Or we can try develop an console application to automate the Office application instead of in the Windows service.

    Hope it is helpful.

    Regards & Fei  


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, September 28, 2015 8:07 AM
    Moderator