开发者

Which Microsoft Word (and Excel) Interop Assembly or DLL Should I Reference?

I'm using VB.NET and the .NET 3.5 framework.

I am trying to automate word and excel using their respective PIAs to get intellisense help, then (since the users don't have the PIA assemblies/DLLs installed) remove the references so that it will work as a COM object call without throwing an error.

I found this article: http://msdn.microsoft.com/en-us/li开发者_JS百科brary/15s06t57.aspx but it doesn't really help me with what version of the assembly/DLL I should use. When I go to add a reference I see something like these:

Which Microsoft Word (and Excel) Interop Assembly or DLL Should I Reference?

then

Which Microsoft Word (and Excel) Interop Assembly or DLL Should I Reference?

then

Which Microsoft Word (and Excel) Interop Assembly or DLL Should I Reference?

Notice all of these highlighted ones all sound similar and there are multiple versions of the assembly. The link I started with suggests the name of the DLL in association to the product version (like WORD version 12 --- Microsoft.Office.Interop.Word.dll) but doesn't say what version of the PIA assembly. So how do I know which one to use?

And a better question: why is this not OBVIOUS somewhere? All I want is Microsoft to say "hey, you want to automate a mail merge with Word 2007? Use [insert meaningful DLL name here (PIA or "tools" assembly?)]. By the way, you can get that DLL here ["here" hyper-linked to the download I need]. Working with computers that may have 2007 or 2010 installed? Make sure you have both DLLs (if that is the case), and here is how you test for it: [insert helpful example].

(e.g. "For Word 14 (i.e. Word 2010), use the Microsoft.Office.Interop.Word DLL version 12.0.0.0" (is this the case? I don't know.)) That should be obvious, and it does not appear to be so.

Maybe it is obvious? Is the version of the DLL the same as the version of the program? (i.e. Microsoft.Office.Interop.Word DLL version 12.0.0.0 =?= WORD version 12)

Maybe I am over-thinking this, but it is still not obvious to me. I'll be happy if you can answer the first question, but if you can explain both, that would be better.


Billy basically answered your question

Office 2010=14.x.x.x

Office 2007=12.x.x.x

Office 2003=11.x.x.x

Office xp=10.x.x.x

Before that, there weren't any PIA's so you'd have to make your own.


Use the class browser to see if the DLL you add exposes the functionality you want (just like you do for every other reference you ever add.

why is this not OBVIOUS somewhere?

So, you want everything you could possibly ever create with the office integration documented somewhere? That doesn't make sense!


There are plenty of ways to skin the cat known as "how do I know which object does X".

  1. use the object browser and search for the methods you desire.
  2. Code it and then add assemblies one at a time - slow and inefficient, but it works

As for figuring out particular bits, Microsoft MSDN, Support, etc all have resources. For mail merge, for example, I found this: http://support.microsoft.com/kb/301659

It is fairly easy to follow references for the code, if mail merge is the issue.

As for the "why is this not obvious somewhere" comment: The Word obects are fairly well documented. Perhaps not to the level you wish to automate Intellisense, but this is a fringe case, IMO. I have been programming the .NET Framework since before the 1.0 release and have yet to have a business case for what you are doing. I also don't know of anyone who has had this type of business case. Following the 80/20 rule, I am not surprised there is not a handholding exercise on this one ... or even full documentation.


It's in the documentation, e.g. DocumentClass:

Namespace: Microsoft.Office.Interop.Word
Assembly: Microsoft.Office.Interop.Word (in microsoft.office.interop.word.dll)

If it has any dependencies on the other assemblies then it ought to add them in itself, or it might prompt you for them at runtime to add.

I'm not sure there's a definitive guide to picking which one, but I'd go for

  • the oldest version of Microsoft.Office.Interop.Word that includes all the functionality you need, so you're compatible with as many Word versions as possible
  • prefer assemblies built with the correct .NET version - I've seen problems with 1.1 assemblies against 4.0 (although not Interop assemblies) but I think generally 1.1 with 2.0 (=3.5's runtime version under the covers) should be OK.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜