1. 程式人生 > >C#與excel互操作 C#與excel互操作的錯誤無法將型別為“Microsoft.Office.Interop.Excel.ApplicationClass”的 COM 物件強制 如果您使用的電腦

C#與excel互操作 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_ROOT\TypeLib\{00020813-0000-0000-C000-000000000046}\1.6 刪除之
 
就可以了。
 
因為我用的是office 2003對應的是1.5,所以刪除1.6