How to solve “Unable to cast COM object of type Microsoft.Office.Interop.Excel.ApplicationClass’ to interface type ‘Microsoft.Office.Interop.Excel._Application’”

这篇文章用于解决C#调用office组建,抛出如下错误的解决方案。

“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 interface with IID '{000208D5-0000-0000-c000-00000000046}' failed due to the followinf error:Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).

 

Solution 1.issue is resolved by deleting the existing configuration properties ->platform options (previously while creating soltion platforms x64 and anycpu  ,settings are copied from x86 ).so even if i run as 64 or any cpu it  behaves as 32 internally.so 

all the target platform solution options were deleted and added freshly and for the setup ->changed the target from x86 to x64

1)right click on solution->configuration propertie->configuration manager->active solution platform->

x86 deletd 
any cpu deleted
x64 deleted

2)again created fresh x86,x64, any cpu and compiled with all options.

3)select appname.setup->view->properties window->Target platform->x64 

 

Solution 2.

Start--> Run --> regedit --> HKEY_CLASSES_ROOT-->TypeLib-->{00020813-0000-0000-C000-000000000046} --> 1.8/1.7 (Delete this)

Solution: This issue can be resolved by deleting an invalid registry key left over from the higher version of Office. Follow the above steps.

Cause: This issue is caused by a left over registry key if you have downgraded your version of Microsoft Office from either Office 2010 to Office 2007, or Office 2013 to Office 2010 or 2007.

 

posted @ 2019-04-15 17:18  Bradwarden  阅读(282)  评论(0)    收藏  举报