Problems with Microsoft Excel COM Automation
So I wrote a method in my company's product a year and a half ago that makes use of Excel 2007's COM automation to export data, only now I'm finding that it's no longer working on machines in the office.
I tested the functionality of the method on my own machine and got the same result.
Digging deeper, I found that when I get as far as
var excel = Excel.Application
If I add a watch on the excel object, I see that every property throws a cast exception.
After doi开发者_Python百科ng some research, I saw something about registry keys that can interfere with automation. I managed to dig through and delete a registry key:
HKEY_CLASSES_ROOT\TypeLib{00020813-0000-0000-C000-000000000046}\1.7
With the following string value defined within:
"PrimaryInteropAssemblyName"="Microsoft.Office.Interop.Excel, Version=14.0.0.0
I then ran the same piece of code again, only this time it ran perfectly fine.
Other machines in the office I've tested the application on have had the same error, only I haven't been able to fix them in the same way.
Has anyone else encountered this before?
ThanksVersion 14 of Office is Office 2010, so I assume that your office has upgraded from 2007 to 2010.
Now, if your computer is a developer machine then I would expect that you have the Microsoft.Office.Interop.Excel, Version=14.0.0.0
assembly on your computer and so your fix works.
However, I guess that the other machines in the office had your code deployed to them so they would have the Microsoft.Office.Interop.Excel, Version=12.0.0.0
assembly, but not the Microsoft.Office.Interop.Excel, Version=14.0.0.0
deployed.
If I were you, I'd check that first.
It may have also been useful to describe the actual error you got in your question, but hopefully my answer helps.
精彩评论