none
Excel Ole Automation Fails Office 365 RRS feed

  • Question

  • I have a c# app that when a user clicks an Export to Excel button it opens Excel, imports a text file, and formats the Excel spreadsheet. However, when running this app on a PC that has Office 365 when the Export to Excel function is called it causes an Exception (Unable to cast COM OBJECT OF TYPE 'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component...). The Excel version of Office 365 is 15.0.0.0. This function call works on Excel version 14.0.0.0 and prior versions (Desktop Excel).

    I'm able to see the Excel object get created on the Office 365 PC:

    Excel.Application objExcel = new Excel.Application();

    The Exception happens when I try to open the Text File using the following method:

    objExcel.Workbooks.OpenText(strFileName,.......);

    Any ideas or help would be appreciated. Thank you.

    Wednesday, April 3, 2019 4:56 PM

All replies

  • Hi cjdlv,

    Thank you for posting here.

    For your question is more related to Excel, you could post a new thread in Excel for Developers forum.

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=exceldev&filter=alltypes&sort=lastpostdesc

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 4, 2019 9:44 AM
  • Wendy

    I respectively disagree that this question is more related to Excel.

    I've created an C# desktop application that collects data and stores data in a database. I then use SQL calls within the C# created app to collect data from the back end database and then send that data to an Excel spreadsheet through Ole Automation. The C# app never had an issues until the user installed Office 365. Prior versions of Office worked (Office 2010).

    My post is directed to C# developers who open Excel from within a C# created application via Ole Automation.

    Thank you.

    Cyrus

    Thursday, April 4, 2019 3:28 PM
  • Cyrus why dont you something like the open xml sdk or npoi to creaye the spreadsheet.  Automating Excel is never easy.

    https://github.com/tonyqus/npoi

    https://docs.microsoft.com/en-us/office/open-xml/open-xml-sdk

    Saturday, April 6, 2019 8:01 AM