[英]Accessing same-named COM-entities from .NET assemblies
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. Fran 我又遇到了一个小问题(我希望如此),而且我不知道如何获得对PowerPoint提供的某些演示文稿属性的访问权限(但是我什至不知道如何在网站上进行搜索或搜索:( ),让我解释一下。我们可以分别通过互操作程序集和ms-office内置的VBA编辑器在C#和VBA中访问TextRange
属性。可以,但是此属性包含两个同名实体- Runs
。VBA允许将其作为方法和属性来访问(此外,内部的Runs
属性对象很有用),但是属性Runs
不能通过interop程序集访问,只能访问Runs()
方法(它返回文本run我已经使用.NET Reflector挖掘了interop程序集,但没有找到与Runs
属性相关的任何内容(尽管具有唯一性而不是方法名称不同的属性具有自己的get_Property()
和set_Property()
方法)。互操作程序集缺少TextRange
接口的Runs
属性。 kly, I'm not sure. 凯莉,我不确定。 :( :(
Can I somehow obtain the access Runs
property from C#? 我可以以某种方式从C#获取访问Runs
属性吗? I'm not familiar with COM, etc, and I hope for your help. 我不熟悉COM等,希望对您有所帮助。 Thanks. 谢谢。
I think you are talking about the Microsoft.Office.Core.TextRange2.Runs() property. 我认为您是在谈论Microsoft.Office.Core.TextRange2.Runs()属性。 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 . 至少在C#4.0之前 ,不能使用C#语言直接访问此属性。 Only Visual Basic supports indexed properties right now. 现在只有Visual Basic支持索引属性。
The workaround is to use get_Runs() instead. 解决方法是改用get_Runs()。
In C# you have to specify where to start and where to end: 在C#中,您必须指定从哪里开始和从哪里结束:
... ...
foreach (TextRange txtrn in txtrng.Runs(0, txtrng.Length)) { foreach(txtrng.Runs(0,txtrng.Length)中的TextRange txtrn){
if(txtrn.Font.Name =="Arial") MessageBox.Show(txtrn.Text); if(txtrn.Font.Name ==“ Arial”)MessageBox.Show(txtrn.Text);
} }
..... .....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.