针对多个MS Word版本的自动化 [英] Automation against multiple MS Word versions

查看:49
本文介绍了针对多个MS Word版本的自动化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果正在开发.NET应用程序,我该如何开发一个使用针对多个Word版本的COM自动化的应用程序?b $ b?对于

示例,Document.Open方法的签名不同于

版本9到版本11(我确定还有其他变体),

我想知道是否有一些简单的方法来处理它。


目前我只关心支持9 -11(即Word 2000,XP和

2003),虽然我想要足够灵活,以便处​​理未来的版本

。开发商现在如何处理这种棘手的情况?


evan stone |软件工程师

----------------------------------------

圣罗莎,加州,美国

If one is developing a .NET application, how can I develop an application
that uses COM automation that targets multiple versions of Word? For
example, the signature for the Document.Open method is different from
version 9 to version 11 (and I''m sure there are other variations as well),
and I''m wondering if there''s some easy way to deal with it.

At present I''m only concerned with supporting 9-11 (i.e. Word 2000, XP, and
2003), though I''d like to be flexible enough to deal with future versions as
well. How are developers dealing with this sticky situation now?

evan stone | software engineer
----------------------------------------
santa rosa, ca, usa

推荐答案

Evan,


不幸的是,对此没有好的解决方案。对于类似

这样的东西,你必须确定你正在使用的Word的版本,并使

适当的调用。这也意味着引用所有三个版本的interop

程序集。


鉴于较新的版本应该支持较旧的接口,你

可能对大多数属性/方法都有一些好运,因为你可以将
始终降低到你支持的界面的最低版本。


但是,如果你需要根据你拥有的版本来做不同的事情,你应该编写一个实用程序类,它将公开

方法界面指针,一个版本,以及

操作的参数,它将包含单独的逻辑。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" Evan Stone" <再********************* @ hotmail.com>在消息中写道

新闻:OS ************* @ tk2msftngp13.phx.gbl ...
Evan,

Unfortunately, there is no good solution for this. For something like
this, you will have to determine the version of Word you are using, and make
the appropriate call. This will also mean having references to the interop
assemblies for all three versions.

Given that the newer versions should support the older interfaces, you
might have some luck for most of the properties/methods, since you can
always downcast to the lowest version of the interface you will support.

However, if you need to do something different based on the version that
you have, you should probably write a utility class which will expose
methods which take the interface pointer, a version, and the parameters for
the operation, which will contain the separate logic.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Evan Stone" <re*********************@hotmail.com> wrote in message
news:OS*************@tk2msftngp13.phx.gbl...
如果正在开发一个。 NET应用程序,我如何开发一个使用针对多个版本的Word的COM自动化的应用程序?例如,Document.Open方法的签名不同于版本9到版本11(我确定还有其他变体),
和我''我想知道是否有一些简单的方法来处理它。

目前我只关心支持9-11(即Word 2000,XP,
,但是很好。开发商现在如何处理这种棘手的情况?

evan stone |软件工程师
----------------------------------------
santa rosa,ca,usa
If one is developing a .NET application, how can I develop an application
that uses COM automation that targets multiple versions of Word? For
example, the signature for the Document.Open method is different from
version 9 to version 11 (and I''m sure there are other variations as well),
and I''m wondering if there''s some easy way to deal with it.

At present I''m only concerned with supporting 9-11 (i.e. Word 2000, XP,
and
2003), though I''d like to be flexible enough to deal with future versions
as
well. How are developers dealing with this sticky situation now?

evan stone | software engineer
----------------------------------------
santa rosa, ca, usa



办公自动化是纯粹的邪恶。


-


Derek Davis
dd ****** @ gmail.com


" Evan Stone" <再********************* @ hotmail.com>在消息中写道

新闻:OS ************* @ tk2msftngp13.phx.gbl ...
Office automation is pure evil.

--

Derek Davis
dd******@gmail.com

"Evan Stone" <re*********************@hotmail.com> wrote in message
news:OS*************@tk2msftngp13.phx.gbl...
如果正在开发一个。 NET应用程序,我如何开发一个使用针对多个版本的Word的COM自动化的应用程序?例如,Document.Open方法的签名不同于版本9到版本11(我确定还有其他变体),
和我''我想知道是否有一些简单的方法来处理它。

目前我只关心支持9-11(即Word 2000,XP,
,但是很好。开发商现在如何处理这种棘手的情况?

evan stone |软件工程师
----------------------------------------
santa rosa,ca,usa
If one is developing a .NET application, how can I develop an application
that uses COM automation that targets multiple versions of Word? For
example, the signature for the Document.Open method is different from
version 9 to version 11 (and I''m sure there are other variations as well),
and I''m wondering if there''s some easy way to deal with it.

At present I''m only concerned with supporting 9-11 (i.e. Word 2000, XP,
and
2003), though I''d like to be flexible enough to deal with future versions
as
well. How are developers dealing with this sticky situation now?

evan stone | software engineer
----------------------------------------
santa rosa, ca, usa



>不幸的是,没有很好的解决方案。


数字。
> Unfortunately, there is no good solution for this.

It figures.
对于像
这样的东西,你将不得不确定您正在使用的Word版本,
进行适当的调用。这也意味着引用了所有三个版本的
互操作程序集。
For something like
this, you will have to determine the version of Word you are using, and make the appropriate call. This will also mean having references to the interop assemblies for all three versions.




是否可以在一个

汇编?这是如何工作的 - VS.NET是否足够聪明,可以为不同版本的程序集创建单独的

名称空间,以便我们可以在运行时区分



或者,创建3个(现在)程序集是否有意义,每个程序集对每个Word Interop程序集都有一个

引用,然后使用Factory模式

实例化一个包装器对象的相应版本,用于处理

其相应的版本?


那么确定的问题是他们有安装
的Word版本,这也是另一个需要处理的问题(但可能更少

棘手)....

evan stone |软件工程师

----------------------------------------

santa rosa,ca,usa



Is it possible to set references to multiple type libraries within one
assembly? How does that work - is VS.NET smart enough to create separate
namespaces for the different versions of the assemblies so we can
differentiate at runtime?

Or, would it make sense to create 3 (for now) assemblies that each have one
reference to each Word Interop assembly, and then use a Factory pattern to
instantiate the appropriate version of a wrapper object designed to handle
its corresponding version?

Then there''s the matter of determining the version of Word that they have
installed, which is another problem to deal with as well (but probably less
tricky)....

evan stone | software engineer
----------------------------------------
santa rosa, ca, usa


这篇关于针对多个MS Word版本的自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆