ICustomFunction Example

Hello,

I am looking for an example of the ICustomFunction that actually works in vb.net 2008. The Help on the web site does not give an example only the function. The sample code in the download also does not have it. I'd like to see it work with multiple arguments such as:

MyFunc(B1,C1:C25,"SomeText")

This has 3 args. This function could do whatever but for all practical purposes i just want to know how to translate the args data so i can process it into a return value weather it is a string, double, or whatever data type.

Thank you,

Troy

Hi,

Thank you for considering Aspose.

Please try the following sample code and attached template file as per your requirement for utilizing ICustomFunction.

Module modTest
    Public Class CustomFunction Implements Aspose.Cells.ICustomFunction

        Function CalculateCustomFunction(ByVal functionName As String, _
                                        ByVal paramsList As System.Collections.ArrayList, _
                                        ByVal contextObjects As System.Collections.ArrayList) As Object _
                                        Implements Aspose.Cells.ICustomFunction.CalculateCustomFunction

            Dim firstParamB1 As Decimal = CType(paramsList.Item(0), Decimal)
            Dim secondParamC1C25 As Array = CType(paramsList.Item(1), Array)
            Dim thirdParamAnyString As String = paramsList.Item(2).ToString()

            ' perform your processing

            Return firstParamB1
        End Function
    End Class

    Sub Main()
        Const WORKBOOK_NAME As String = "..\..\..\test.xls"

        'Open the workbook
        Dim wbk As New Aspose.Cells.Workbook
        wbk.Open(WORKBOOK_NAME)

        wbk.CalculateFormula(False, New CustomFunction)
        wbk.Worksheets(0).Cells("A1").PutValue(wbk.Worksheets(0).Cells("A1").Value)

        'Save the workbook
        wbk.Save(WORKBOOK_NAME)

    End Sub
End Module

We will also include the example code to our online documentation soon. Also, we will provide an online demo for it soon.

Thank You & Best Regards,