UDF with ParamArray in F#

49 views
Skip to first unread message

Thomas Rizzo

unread,
Sep 4, 2022, 12:27:05 PM9/4/22
to Excel-DNA
Hi, I'm converting a C# addin to F# and I'm having trouble with `params` parameters. In C#, this works fine-- I get the expected behavior in Excel where I can add any number of comma separated parameters. But with the F# version, I just get 1 parameter that's an array.

Thanks,
Tom

   [<AbstractClass>][<Sealed>]
    type Udf =
        [<ExcelFunction(Name = "VarParamTest")>]
        static member VariablParams([<ExcelArgument(Name = "Params")>][<ParamArray>] p: obj[]) = p
           

And here's the AutoOpen function I'm using:

open ExcelDna.Registration.FSharp
open ExcelDna.IntelliSense

type FsAsyncAddIn() =
    interface IExcelAddIn with
        member _.AutoOpen() =

            // The overload selection and delegate conversions performed by F# are not intuitive.
            let paramConvertConfig =
                ParameterConversionConfiguration()
                    .AddParameterConversion(
                        Func<Type, ExcelParameterRegistration, LambdaExpression>(
                            FsParameterConversions.FsOptionalParameterConversion
                        ),
                        null
                    )

            ExcelRegistration.GetExcelFunctions()
            |> fun fns -> ParameterConversionRegistration.ProcessParameterConversions(fns, paramConvertConfig)
            |> FsAsyncRegistration.ProcessFsAsyncRegistrations
            |> AsyncRegistration.ProcessAsyncRegistrations
            |> MapArrayFunctionRegistration.ProcessMapArrayFunctions
            |> ExcelRegistration.RegisterFunctions

            IntelliSenseServer.Install()

        member _.AutoClose() = IntelliSenseServer.Uninstall()
Reply all
Reply to author
Forward
0 new messages