C#与excel互操作的错误无法将类型为“Microsoft.Office.Interop.Excel.ApplicationClass”的 COM 对象强制

C#与excel互操作的错误无法将类型为“Microsoft.Office.Interop.Excel.ApplicationClass”的 COM 对象强制
如果您使用的电脑要操作的是office2003而之前使用过office2007使用此方法可解决您的问题
无法将类型为“Microsoft.Office.Interop.Excel.ApplicationClass”的 COM 对象强制转换为接口类型“Microsoft.Office.Interop.Excel._Application”。此操作失败的原因是对 IID 为“{000208D5-0000-0000-C000-000000000046}”的接口的 COM 组件调用 QueryInterface 因以下错误而失败: 库没有注册。 (异常来自 HRESULT:0x8002801D (TYPE_E_LIBNOTREGISTERED))。英文版的异常消息如下:
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: could not be found. (Exception from HRESULT: 0x80030002 (STG_E_FILENOTFOUND)).
 
出现的原因可能是安装office时安装过不同版本造成的
 
本人安装的是office 2003,并安装过office2007的兼容包,也安装过office visio 2007
 
解决办法:
 
在注册表中找到:
 
?HKEY_CLASSES_ROOTTypeLib{00020813-0000-0000-C000-000000000046}1.6 删除之
 
就可以了。
 
因为我用的是office 2003对应的是1.5,所以删除1.6
 
office 2007对应的是1.6,所以要根据情况判断。
放下电子产品,每天进步一点点
原文地址:https://www.cnblogs.com/vienna/p/3608981.html