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. 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.
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.
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);
}
.....
精彩评论