在Word中将Word Interop类映射到TextBox吗? [英] The mapped Word Interop class to TextBox in MS Word?

查看:92
本文介绍了在Word中将Word Interop类映射到TextBox吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Word Interop库具有许多映射到MS Word中相应对象的映射类,例如段落,表格,图表,选择.

但是我找不到映射到TextBox的类,能否让我知道它的名称和它在Word Interop库中的位置?

上面的类"一词实际上称为接口",它与.NET中的Interface不同,我不知道为什么,但是这些接口就像在.NET中确实是类一样工作(特别是,我们可以创建它们的实例吗?).

谢谢!

Word Interop library has many mapped classes to the corresponding objects in MS Word such as Paragraph, Table, Chart, Selection.

But I don''t find out the mapped class to TextBox, could you let me know its name and its location in Word Interop library?

The term ''class'' above in fact is called ''interface'' which is not like Interface in .NET, I don''t know why it is but those interfaces work as if they are really classes in .NET (especially, we can create their instances?).

Thank you!

推荐答案

首先,从技术上说,许多类型的Microsoft.Office.Interop.Word是接口,但它们的命名并不符合接口的命名约定.出于好奇,我刚刚引用并打开了Microsoft.Office.Interop.Word v.12.0.0.0并可以确认.但是,您不应感到困惑.接口是接口,无论有人如何命名它们.可能是由于原始Word API的样式所致,这是历史原因导致的.

让我们整理一下.您了解吗,关于对象,接口类型只能用作对象的编译时类型,因为不能实例化接口.接口引用所代表的这些对象的运行时类型只能是类还是结构?每次在运行时使用任何实际存在的接口引用时,您实际上都在使用一个运行时类型是实现该接口的类或结构的对象.没有什么神秘的或不清楚的.这是使用接口以及抽象类的通用原理,这是一个非常基本的OOP原理.



正确的模式是这样的:

First, many types of the Microsoft.Office.Interop.Word are technically the interfaces but are named not according to the naming conventions of interfaces. I just referenced and opened, out of curiosity, Microsoft.Office.Interop.Word v.12.0.0.0 and can confirm it. However, you should not be confused. Interfaces are interfaces, no matter how someone named them. Probably this is due to the style of original Word API, something existing by historical reasons.

Let''s sort it out. Do you understand that, when it comes to objects, interface types can serve only as the compile-time types of objects, as interfaces cannot be instantiated; and run-time types of these objects represented by the interface references could be only classes or structures? Every time you work with any really existing interface reference during run time, you really work with an object which run time type is a class or a structure implementing the interface. There is nothing mysterious or unclear about it; this is the universal principle of using interfaces, as well as abstract classes, a very basic OOP principle.



The right pattern is this:

interface IMyInterface {
    void MyMethod(/* ... */);
    //...
}

class MyClass : IMyInterface {
    void IMyInterface.MyMethod(/* ... */) {}
    //...
}

structure MyStructure : IMyInterface {
    void IMyInterface.MyMethod(/* ... */) {}
    //...
}

//...

IMyInterface objectOne = new MyClass(/* ... */); // don't commit a crime of having typecast here
IMyInterface objectTo = new MyStructure(/* ... */); // don't commit a crime of having typecast here
objectOne.MyMethod(/* ... */); //do you get it finally?

//don't commit another crime here:
MyClass instance = (MyClass)objectOne;
instance.//.... crime is actually here: if you want using interfaces, use all implementing types
// via interface references only; this is not a strict rule, but not following it is a bad style



[END EDIT]

关于TextBox —不,在整个程序集中没有这样的类型,很难理解为什么有人在Word互操作中会需要这样的东西.

但是,存在接口Microsoft.Office.Interop.Word.TextInput.也许,这就是您要寻找的.请参阅:
http://msdn.microsoft. com/en-us/library/microsoft.office.interop.word.textinput%28v = office.14%29.aspx [ http://msdn.microsoft. com/en-us/library/microsoft.office.interop.word.textinput%28v = Office.11​​%29.aspx [



[END EDIT]

As to the TextBox — no, there is no such type in the whole assembly, and it''s hard to understand why would anyone would need such thing in Word interoperation.

However, there is the interface Microsoft.Office.Interop.Word.TextInput. Maybe, this is what you are looking for. Please see:
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.textinput%28v=office.14%29.aspx[^],
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.textinput%28v=Office.11%29.aspx[^].

—SA


这篇关于在Word中将Word Interop类映射到TextBox吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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