Accessing CustomProperties on a named sheet

I'm trying to access a custom property in a sheet using the property name, but it seems that this is not supported (at least not in C #, I've seen others report that it works in VB, and the documentation also says this ). Can anyone confirm that this doesn't work in C #? Here's some sample 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 the workaround is just some method that iterates over all the properties and finds the correct one, but I'd really like to avoid the extra overhead.

+3


source to share


1 answer


Can anyone confirm that this doesn't work in C #?

Just tried the Office 2013 preview and version 15 of the Interop API and I can confirm that this doesn't work in C # (throws a COMException

with a "Type mismatch" message).

I checked the documentation which says that it should be perfectly legal to use the key name as an index for the indexer Item

from the docs for the property CustomProperties.Item

, it indicates that the following index is available:

CustomProperty this[
    Object Index
] { get; }

      



... and the following text in the docs states:

Parameters

Index

A 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're experiencing is likely to be a bug.

+3


source







All Articles