Office 365计算机上的Office自动化应用程序失败 [英] Office Automation App Fails On Office 365 Machines

查看:138
本文介绍了Office 365计算机上的Office自动化应用程序失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Excel进行COM自动化的应用程序。 我使用来自C#的Microsoft.Office.Interop.Excel。

如果安装了Office 2010,应用程序可以正常工作。 在安装了Office 365的计算机上,出现以下错误:

I have an application that does COM automation with Excel.  I use Microsoft.Office.Interop.Excel from C#.
The application works fine if Office 2010 is installed.  On machines with Office 365 installed, I get the following error:

System.InvalidCastException:无法将类型为"System .__ ComObject"的COM对象强制转换为接口类型"Microsoft.Office.Interop"。 Excel.Application"。此操作失败,因为由于以下错误,IID为"{000208D5-0000-0000-C000-000000000046}"
的接口的COM组件上的QueryInterface调用失败:加载类型库/ DLL时出错。 (HRESULT异常:0x80029C4A(TYPE_E_CANTLOADLIBRARY))。

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Excel.Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).

重现代码很简单:

使用System;

使用System.Collections.Generic;

使用System.Data;

使用System.Diagnostics;

使用System.IO;

使用System.Runtime.InteropServices;

使用System.Text;

使用System.Threading;

使用Excel = Microsoft。 Office.Interop.Excel;

using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using Excel = Microsoft.Office.Interop.Excel;

命名空间TestExcel

{

   课程计划

    {

        static void Main(string [] args)

        {

            //启动Excel并获取Application对象。

            Excel.Application excelApp = new Excel.Application(); //在这里失败

namespace TestExcel
{
    class Program
    {
        static void Main(string[] args)
        {
            // Start Excel and get Application object.
            Excel.Application excelApp = new Excel.Application(); // Fails here

            //设置一些属性。

            excelApp.Visible = false;

            excelApp.DisplayAlerts = false;

            // Set some properties.
            excelApp.Visible = false;
            excelApp.DisplayAlerts = false;

            excelApp.Quit();

            Marshal.ReleaseComObject(excelApp);

        }
    } b $ b}

            excelApp.Quit();
            Marshal.ReleaseComObject(excelApp);
        }
    }
}

任何想法如何解决这个问题?

Any ideas how to fix this?

Matt

Matt

推荐答案

Hi Matt。

Hi Matt.

哪个版本的你引用COM吗?

Which version of COM do you reference?

如果你在你的应用程序中引用了15.0版本,我建议你试试这个:

If you reference version 15.0 in your application, I recommend that you could try this way:

1.删除Excel引用(Microsoft.Office.Interop.Excel)。版本15.0。

1.Delete the Excel reference (Microsoft.Office.Interop.Excel). Version 15.0.

2.添加Excel参考(旧版本。版本14.0)。

2.Add the Excel reference (older one. Version 14.0).

希望有所帮助。

如果您的申请仍然导致此错误,请告知我们。

If your application still causes this error, please let me know.

谢谢。


这篇关于Office 365计算机上的Office自动化应用程序失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆