I'm using VB.NET and the .NET 3.5 framework.
我正在使用VB.NET和.NET 3.5框架。
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.
我试图使用各自的PIA自动化word和excel以获得intellisense帮助,然后(因为用户没有安装PIA程序集/ DLL)删除引用,以便它可以作为COM对象调用而不会抛出错误。
I found this article: http://msdn.microsoft.com/en-us/library/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:
我发现这篇文章:http://msdn.microsoft.com/en-us/library/15s06t57.aspx,但它并没有真正帮助我使用什么版本的程序集/ DLL。当我去添加引用时,我会看到类似这样的内容:
then
then
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?
请注意所有这些突出显示的声音都相似,并且有多个版本的程序集。我开始的链接建议与产品版本相关联的DLL的名称(如WORD版本12 --- Microsoft.Office.Interop.Word.dll),但没有说明什么版本的PIA程序集。那么我怎么知道使用哪一个?
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].
还有一个更好的问题:为什么这不是某个地方的明显?我想要的只是微软说“嘿,你想自动化与Word 2007的邮件合并?使用[在这里插入有意义的DLL名称(PIA或”工具“程序集?)]。顺便说一下,你可以在这里获取该DLL [ “这里”超链接到我需要的下载]。使用可能安装了2007或2010的计算机?确保你有两个DLL(如果是这种情况),以下是你如何测试它:[insert helpful例]。
(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.
(例如“对于Word 14(即Word 2010),使用Microsoft.Office.Interop.Word DLL版本12.0.0.0”(这是这种情况吗?我不知道。))这应该是显而易见的,它不会似乎是这样。
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)
也许这很明显? DLL的版本是否与程序版本相同? (即Microsoft.Office.Interop.Word DLL版本12.0.0.0 =?= WORD版本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.
也许我过度思考这个问题,但对我来说仍然不是很明显。如果你能回答第一个问题,我会很高兴,但如果你能解释这两个问题,那就更好了。
4 个解决方案
#1
1
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.
使用类浏览器查看您添加的DLL是否公开了您想要的功能(就像您为所有其他参考添加的那样)。
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!
那么,您希望在办公室集成中可能创建的所有内容都记录在某处吗?这没有意义!
#2
4
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.
在那之前,没有任何PIA,所以你必须自己做。
#3
1
There are plenty of ways to skin the cat known as "how do I know which object does X".
有很多方法可以让猫皮肤被称为“我怎么知道X对象是什么”。
- use the object browser and search for the methods you desire.
- 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
至于确定特定位,Microsoft MSDN,支持等都有资源。例如,对于邮件合并,我发现了这个: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.
至于“为什么这在某处并不明显”评论:Word对象的记录相当充分。也许不是你想要自动化Intellisense的水平,但这是一个边缘情况,IMO。我从1.0版本发布之前一直在编写.NET Framework,并且还没有针对您正在做的业务案例。我也不知道有这种商业案例的人。遵循80/20规则,我并不感到惊讶的是,没有关于这个的手持操作......甚至是完整的文档。
#4
1
It's in the documentation, e.g. DocumentClass:
它在文档中,例如的DocumentClass:
Namespace: Microsoft.Office.Interop.Word
Assembly: Microsoft.Office.Interop.Word (in microsoft.office.interop.word.dll)命名空间:Microsoft.Office.Interop.Word程序集:Microsoft.Office.Interop.Word(在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.
最旧版本的Microsoft.Office.Interop.Word,包含您需要的所有功能,因此您可以与尽可能多的Word版本兼容
更喜欢使用正确的.NET版本构建的程序集 - 我已经看到了针对4.0的1.1程序集的问题(虽然不是Interop程序集)但我认为通常1.1和2.0(= 3.5的运行时版本)应该没问题。
#1
1
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.
使用类浏览器查看您添加的DLL是否公开了您想要的功能(就像您为所有其他参考添加的那样)。
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!
那么,您希望在办公室集成中可能创建的所有内容都记录在某处吗?这没有意义!
#2
4
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.
在那之前,没有任何PIA,所以你必须自己做。
#3
1
There are plenty of ways to skin the cat known as "how do I know which object does X".
有很多方法可以让猫皮肤被称为“我怎么知道X对象是什么”。
- use the object browser and search for the methods you desire.
- 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
至于确定特定位,Microsoft MSDN,支持等都有资源。例如,对于邮件合并,我发现了这个: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.
至于“为什么这在某处并不明显”评论:Word对象的记录相当充分。也许不是你想要自动化Intellisense的水平,但这是一个边缘情况,IMO。我从1.0版本发布之前一直在编写.NET Framework,并且还没有针对您正在做的业务案例。我也不知道有这种商业案例的人。遵循80/20规则,我并不感到惊讶的是,没有关于这个的手持操作......甚至是完整的文档。
#4
1
It's in the documentation, e.g. DocumentClass:
它在文档中,例如的DocumentClass:
Namespace: Microsoft.Office.Interop.Word
Assembly: Microsoft.Office.Interop.Word (in microsoft.office.interop.word.dll)命名空间:Microsoft.Office.Interop.Word程序集:Microsoft.Office.Interop.Word(在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.
最旧版本的Microsoft.Office.Interop.Word,包含您需要的所有功能,因此您可以与尽可能多的Word版本兼容
更喜欢使用正确的.NET版本构建的程序集 - 我已经看到了针对4.0的1.1程序集的问题(虽然不是Interop程序集)但我认为通常1.1和2.0(= 3.5的运行时版本)应该没问题。