工作表上访问CustomProperties来与名称 [英] Accessing CustomProperties on Worksheet with Name
问题描述
我试图通过使用属性的名称来访问工作表自定义属性,但它似乎不支持这种(在C#中至少不是,我看到其他人报告说,它在VB和文件还称所以)。有人可以证实,这不是工作在C#?下面是示例代码:
activeWorkSheet.CustomProperties.Add(测试,123);
//通过索引访问工作,但名字没有。
//文档说按名称访问应该可以
变种工作= activeWorkSheet.CustomProperties.Item [1] .value的;
VAR doenstWork = activeWorkSheet.CustomProperties.Item [测试]值。
我知道,一个解决方法是只是一些方法在所有属性迭代,并找到合适的人,但我真的想避免任何额外的开销。
有人可以证实这不是工作在C#?
块引用>
刚试过与Office 2013预览和互操作性API的15版本,我可以证实,这不起作用在C#(抛出一个
收到COMException
与类型不匹配的消息)。
我已经检查了<一个HREF =http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.customproperties.item%28v=office.14%29.aspx相对=nofollow>文件一>,其中规定,它应该是完全合法的使用密钥名称作为指数为
项目
索引 - 从文档的CustomProperties.Item
属性,它指出了以下索引可用:CustomProperty的这种[
对象指数
] {搞定; }
...并在下面的文本,该文件规定:
参数
的首页的
键入
System.Object的
需要的对象。在名称的对象或索引号。
块引用>
......如此以来,文档指出名字是一个有效的关键,其行为我们的经验可能会是一个错误。
I'm trying to access a custom property on a worksheet by using the name of the property, but it seems this is not supported (at least not in C#, I saw others reporting that it works in VB and documentation also says so). Can someone confirm that this is not working in C#? Here is example code:
activeWorkSheet.CustomProperties.Add("Test", 123); // Accessing by index works, but by name it doesn't. // The documentation says access by name should be possible var works = activeWorkSheet.CustomProperties.Item[1].Value; var doenstWork = activeWorkSheet.CustomProperties.Item["Test"].Value;
I know that a workaround is just some method that iterates over all the properties and finds the right one, but I would really like to avoid any additional overhead.
解决方案Can someone confirm that this is not working in C#?
Just tried with Office 2013 preview and version 15 of the Interop API, and I can confirm that this does not work in C# (throws a
COMException
with the message of "Type mismatch").I have checked the documentation, which states that it should be perfectly legal to use the key name as index for the
Item
indexer - from the docs for theCustomProperties.Item
property, it states that the following indexer is available:CustomProperty this[ Object Index ] { get; }
... and in the following text, the docs states:
Parameters
Index
Type:
System.Object
Required Object. The name or index number of the object.
... so since the documentation states that the name is a valid key, the behavior we experience might likely be a bug.
这篇关于工作表上访问CustomProperties来与名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!