从 .NET 程序集中访问同名 COM 实体
我又遇到了一个小问题(我希望如此),我不知道如何访问 PowerPoint 提供的某些演示文稿属性(但是我什至不知道如何在 google 上搜索它或在网站上搜索它:( ),让我解释一下。我们可以分别通过互操作程序集和 ms-office 内置的 VBA 编辑器访问 TextRange
属性。两个同名实体 - Runs
允许将其作为方法和属性进行访问(此外,Runs
属性对象内部很有用),但是属性 >Runs
无法通过互操作程序集访问,只能访问 Runs()
方法(并且它返回文本运行对象),我使用 .NET Reflector 挖掘了互操作程序集。但我没有找到与 Runs 属性相关的任何内容(尽管具有不同唯一名称而不是方法名称的属性有自己的 get_Property() 和 set_Property() ) > 方法)。互操作程序集似乎缺少 TextRange
接口的 Runs
属性。坦白说,我不确定。 :(
我可以以某种方式从 C# 获取访问 Runs
属性吗?我对 COM 等不熟悉,希望得到您的帮助。谢谢。
I've got a tiny (I hope) problem again, and I don't know how to obtain access to some presentation properties provided by PowerPoint (however I don't even know how to google it or search it at the site :( ) from C#. Let me explain. We can access a TextRange
property both in C# and VBA, via an interop assembly and ms-office-built-in VBA editor respectively. It's ok, but this property contains two same-named entities - Runs
. VBA allows to access it as a method and as a property (moreover, Runs
property object insides are useful), but the property Runs
in not accessible via the interop assembly, Runs()
method can be accessed only (and it returns text run objects). I've digged in the interop assembly using .NET Reflector but I have not found anything related to the Runs
property (though properties with different unique rather than methods names have own get_Property()
and set_Property()
methods). It seems that the interop assembly is missing the Runs
property for TextRange
interface. Frankly, I'm not sure. :(
Can I somehow obtain the access Runs
property from C#? I'm not familiar with COM, etc, and I hope for your help. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您正在谈论 Microsoft.Office.Core.TextRange2.Runs() 属性。它是一个带有两个参数的属性:start 和 length。这样的属性无法在 C# 语言中直接访问,至少不能 直到 C# 4.0。目前只有 Visual Basic 支持索引属性。
解决方法是使用 get_Runs() 代替。
I think you are talking about the Microsoft.Office.Core.TextRange2.Runs() property. It is a property that takes two arguments, start and length. Such a property is not directly accessible in the C# language, at least not until C# 4.0. Only Visual Basic supports indexed properties right now.
The workaround is to use get_Runs() instead.
在 C# 中,您必须指定从哪里开始和在哪里结束:
...
foreach (TextRange txtrn in txtrng.Runs(0, txtrng.Length))
{
if(txtrn.Font.Name ==“Arial”)
MessageBox.Show(txtrn.Text);
}
......
In C# you have to specify where to start and where to end:
...
foreach (TextRange txtrn in txtrng.Runs(0, txtrng.Length))
{
if(txtrn.Font.Name =="Arial")
MessageBox.Show(txtrn.Text);
}
.....