As a pragmatic approach, i would recommend this:
* Allow your function to accept and process string values for that parameter, and internally convert to your enum value or return a #VALUE error.
* Add a nice description of the allowed options in your [ExcelArgument(Description="...")] attribute.
If you really want to emulate the built-in functions like the ones you describe, you enter into a bit of a minefield.
There are two issues here:
* Deciding how to register and handle the enum-related parameter in the UDF registration.
* Making a pop-up list for the possible values that a parameter can take.
Excel does not allow us to register a user-defined function with such a special parameter type.
So you'll have to accept string or double as the parameter type for your function, and convert these to your enum type yourself, and deal with invalid values you might receive etc.
If having to pass a string or number in for the enum values seems terrible, you might set up define names for your enum values that correspond to the different string or number values. These will show in the Excel dropdown after you type the first letter,
so that might be quite usable, though it won't be obvious for your user what the options are unless they type the right prefix. One downside to making names is that they are linked to the workbook, and not your add-in.
One hackish way to allow your formula to read:
=MyFunc(MY_ENUM_1)
instead of
=MyFunc("MY_ENUM_1")
or
=MyFunc(1)
is to create functions with the names of the enums, say
[ExcelFunction(IsHidden=true)]
public static object MY_ENUM_1() => "";
and the get their RegisterId and store these internally somewhere, say a dictionary _enumRegIds:
var regId1 = XlCall.Excel(XlCall.xlfEvaluate, "MY_ENUM_1");
_enumRegIds[regId1] = MyEnum.MY_ENUM_1;
These RegisterIds can be kept in a dictionary in your add-in, and used to look up the right enum value when the function is called:
public static string MyFunc(object input)
{
MyEnum inputEnum;
if (_enumRegIds.TryGetValue(input, out inputEnum))
{
return $"Input is an Enum value: {inputEnum}";
}
else
{
return $"Input is {input}";
}
}
This does not address the pop-up issue yet. That would have to be done by improving the Excel-DNA IntelliSense extension to know about special parameters that should be presented with a list of values. I can't think
of any blocking technical issues on adding this to the IntelliSense, but it would be a fair amount of work to implement.
-Govert