Back to Devexpress

ICustomFunctionDescriptionsRegisterService Interface

officefileapi-devexpress-dot-spreadsheet-dot-functions-512c9c1f.md

latest4.2 KB
Original Source

ICustomFunctionDescriptionsRegisterService Interface

Provides captions and text descriptions for the Function Argument dialog invoked for the custom function (UDF).

Namespace : DevExpress.Spreadsheet.Functions

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
public interface ICustomFunctionDescriptionsRegisterService
vb
Public Interface ICustomFunctionDescriptionsRegisterService

Remarks

To get the service of the ICustomFunctionDescriptionsRegisterService type, use the GetService<T> method of the workbook.

To specify function and argument descriptions for a specific custom function, call the ICustomFunctionDescriptionsRegisterService.RegisterFunctionDescriptions method. The method requires a CustomFunctionArgumentsDescriptionsCollection object that is the collection of items containing the type and description for each argument. The order of argument descriptions in the collection is the same as the order of arguments in the function signature.

Example

This example shows how to use ICustomFunctionDescriptionsRegisterService for the SPHEREMASS custom function defined in the following example: Spreadsheet Document API Examples.

csharp
SphereMassFunction customFunction = new SphereMassFunction();
if (!workbook.CustomFunctions.Contains(customFunction.Name))
{
    workbook.CustomFunctions.Add(customFunction);
    // Get a service to specify the function description.
    ICustomFunctionDescriptionsRegisterService service = (ICustomFunctionDescriptionsRegisterService)workbook.GetService(typeof(ICustomFunctionDescriptionsRegisterService));
    if (service == null)
        return;
    CustomFunctionArgumentsDescriptionsCollection arguments = new CustomFunctionArgumentsDescriptionsCollection();
    arguments.Add(new CustomFunctionArgumentDescription("Radius", "Radius of a sphere, m", "number")); 
    arguments.Add(new CustomFunctionArgumentDescription("Density", "Material density, kg/m3", "number"));
    service.RegisterFunctionDescriptions("SPHEREMASS", "Calculates the mass of a sphere made of a certain material.", arguments);
}
vb
Dim customFunction As New SphereMassFunction()
If (Not workbook.CustomFunctions.Contains(customFunction.Name)) Then
    workbook.CustomFunctions.Add(customFunction)
    ' Get a service to specify the function description.
    Dim service As ICustomFunctionDescriptionsRegisterService = CType(workbook.GetService(GetType(ICustomFunctionDescriptionsRegisterService)), ICustomFunctionDescriptionsRegisterService)
    If service Is Nothing Then
        Return
    End If
    Dim arguments As New CustomFunctionArgumentsDescriptionsCollection()
    arguments.Add(New CustomFunctionArgumentDescription("Radius", "Radius of a sphere, m", "number"))
    arguments.Add(New CustomFunctionArgumentDescription("Density", "Material density, kg/m3", "number"))
    service.RegisterFunctionDescriptions("SPHEREMASS", "Calculates the mass of a sphere made of a certain material.", arguments)
End If

See Also

ICustomFunctionDescriptionsRegisterService Members

DevExpress.Spreadsheet.Functions Namespace