简体   繁体   English

从.NET程序集访问同名的COM实体

[英]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.

相关问题 来自不同命名空间的同名对象的可重用功能代码? - Reusable Function Code For Same-Named Objects From Different Namespaces? 使用LINQ从同名XDocument元素获取属性 - Getting attributes from same-named XDocument elements using LINQ 在PHP中通过COM访问.NET程序集 - Accessing .NET assemblies via COM in PHP 当存在同名的命名空间(在当前范围内)时,如何引用它们中的任何一个? - When same-named namespaces exist (in current scope), how to refer any of them? 是否有特定原因在类中不允许使用同名属性和方法但允许作为扩展方法? - Is there a specific reason same-named properties and methods are disallowed in classes but allowed as extension methods? 可以在显式接口实现中引用同名的隐式属性吗? - Can one reference a same-named implicit property in an explicit Interface implementation? Windows Forms .NET中的强命名程序集 - Strong named assemblies in Windows Forms .NET Project 2003和.NET COM主互操作程序集 - Project 2003 and .NET COM Primary Interop Assemblies .NET / Security:限制运行时加载的程序集访问某些API - .NET/Security: Limiting runtime-loaded assemblies from accessing certain APIs 从不同的程序集访问静态变量 - Accessing a static variable from different assemblies
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM