How to implement Optional parameters (with default values) and Nullable parameters
how to use this function? Give an example? •Optional parameters (with default values), 'params' parameters and Nullable parameters
Give an example? Thanks!
There are lots of parameter-related examples here: https://github.com/Excel-DNA/Registration/blob/master/Source/Samples/Registration.Sample/ParameterConversionExamples.cs
Where are you stuck?
I use this formula in Excel and can't return the default value ""Hello World!".
[ExcelFunction] public static string dnaOptionalString(string optOptTest = "Hello World!") { return optOptTest; }
Where is the mistake. What do I need to configure?
Do I need to register these functions separately in a special way?
I have a another question, how to get the Worksheet where Range is located via ExcelReference?
To use the Excel-DNA Registration extensions (which support optional parameters) you need to change your project to use 'explicit registration'. See the walkthrough here: https://github.com/Excel-DNA/Registration/blob/master/README.md
Sorry,I have read this article, but still do not understand。
And I also read the source code. Find The Function [ public` static IEnumerable<ExcelFunctionRegistration> ProcessParameterConversions(this IEnumerable<ExcelFunctionRegistration> registrations, ParameterConversionConfiguration conversionConfig); ]
Should I use this extension convert the function parameter before registration.
Like This:
I do not know How to set the ParameterConversionConfiguration.
Govert, thanks a lot for your work, but this part is not clear enough. Are optional arguments still a work in progress? (you're mentioning here some casting issues: https://github.com/Excel-DNA/Registration/blob/master/Source/Samples/Registration.Sample/ParameterConversionExamples.cs
Otherwise, could you amend the documentation and give some examples? I.e. in the walkthrough you're showing how to update a help page by adjusting that specific argument generally for functions. I think what SkyChen91 is looking for (and so am I) is a neat way to set arguments/parameters for individual functions as a default to the value specified in that function.
E.g. When setting defaults as in the example above
[ExcelFunction] public static string dnaOptionalString(string optOptTest = "Hello World!") { return optOptTest; }
Value of
optOptTest stays empty "" and can't be updated to "Hello World!"?. We could check for emptyness as a workaround and update it that way below inside the function, but am I right to assume that the information "Hello World!" in this case is only overhead yet and can't be retrieved inside the function? Or how would you do that? If it's possible, a simple example would be great!
@lbnewre When I run the Registration sample, the optional string function works fine, and I get see the default value returned to Excel when calling it as =dnaOptionalString() from a sheet.
Have you tested the Registration sample?
Are you using the Registration extension in your add-in, according to the walkthrough here: https://github.com/Excel-DNA/Registration/blob/master/README.md
(You need a few extra steps in your add-in like ExplicitRegistraiton=true, and dealing with the RegisterFunctions explicitly etc.)
I think there are some quirks with the conversions in some cases, but optional strings with defaults work in the Registration sample on my computer.
the samples have been moved to https://github.com/Excel-DNA/Samples/blob/master/Registration.Sample/ParameterConversionExamples.cs