无法投放COM对象(EXCEL) [英] Unable to cast COM object (EXCEL)

查看:46
本文介绍了无法投放COM对象(EXCEL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序刚刚添加了一个新功能,以允许将数据导出到Excel.它在一台设备上运行良好,但是当我们在第二台设备上实现该功能时,会出现以下错误:

My application just added a new function to allow export data into Excel. It worked fine on one device but when we implement it on the second one the following error appeared:

错误消息:

System.InvalidCastException:无法转换类型为COM的对象'Microsoft.Office.Interop.Excel.ApplicationClass'到接口类型'Microsoft.Office.Interop.Excel._Application'.该操作失败因为接口的COM组件上的QueryInterface调用IID为'{000208D5-0000-0000-C000-000000000046}'的广告因出现以下错误:加载类型库/DLL时出错.(来自的例外HRESULT:0x80029C4A(TYPE_E_CANTLOADLIBRARY)).

System.InvalidCastException: Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' 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)).

推荐答案

该错误可能表明它无法加载DLL,但是如果您尝试加载问题所在的Excel.使用注册表无法找到"EXCEL.EXE".

The error may say it can't load a DLL but if you are trying to load Excel that is where the problem is. It can't find "EXCEL.EXE" using the registry.

对于某些人来说,可以通过添加\删除程序"进行简单的Office修复:修改"足以解决问题.

For some people, doing a simple Office repair from Add\Remove programs: Modify is enough to fix the problem.

如果您已经尝试过Office修复,则可以通过编辑注册表来手动修复它.

If you have already tried an Office repair then you can fix it manually by editing the registry.

以管理员身份打开Regedit,然后转到:

Computer\HKEY_CLASSES_ROOT\TypeLib\{00020813-0000-0000-C000-000000000046}\

这是显示Excel安装位置的位置.此时,如果看到多个版本,"1.9","1.8","1.7",则需要删除多余的条目.例如,Excel 2019的值为"1.9",因此您将删除不再安装的其他版本.

This is the location that shows where Excel is installed. At this point if you see multiple versions, "1.9", "1.8", "1.7" then you need to remove the extra entries. For example Excel 2019 is "1.9" so you would remove other versions no longer installed.

一旦只有一个版本,您还需要检查位数.我已经从32位迁移到64位,但是两个键仍然存在

Once you have only one version you also need to check the bitness. I had moved from 32-bit to 64-bit but both keys were still present

Computer\HKEY_CLASSES_ROOT\TypeLib\{00020813-0000-0000-C000-000000000046}\1.9\0\Win32
Computer\HKEY_CLASSES_ROOT\TypeLib\{00020813-0000-0000-C000-000000000046}\1.9\0\Win64

我删除了Win32密钥,然后一切又开始正常工作.在这些键中,默认值显示"EXCEL.EXE"的完整路径.确保路径正确.

I removed the Win32 key and everything began working again. Inside these keys the default value shows the full path to "EXCEL.EXE". Ensure that path is correct.

这篇关于无法投放COM对象(EXCEL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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