且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

一个excel VSTO加载项可以与excel 2007和2010兼容吗?

更新时间:2023-12-05 21:14:52

I already answered this for Word, but it also applies to Excel:

If you want to deploy to Office 2010 AND 2007, you have to add references to the v12.0 assemblies (Microsoft.Office.Interop.Excel and Office).

Now there is still the problem that your addin will require the 2007 PIA, but they won't install if you only have Office 2010 on the target machine (because they have Office 2007 as a prerequisite). To solve this you have to set Embed Interop Assemblies = true for those two dlls (in the reference properties) and use dynamic for the types you can't directly reference anymore.

This causes some "weirdness" with Intellisense not finding methods etc., but it should not be a big problem -at least now PIA are not required anymore and your addin will deploy on both 2007 and 2010 (you'll have to take care of the installer as well, but that is a whole other story).

It's a bit of a mess, but if you are working with VSTO I suppose you are used to this kind of stuff :-)