//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); GrapeCity.Documents.Excel.Workbook.AddCustomFunction(new MyIsErrorFunctionX()); IWorksheet worksheet = workbook.Worksheets[0]; worksheet.Range["A1"].Value = CalcError.Num; worksheet.Range["A2"].Value = 100; worksheet.Range["B1"].Formula = "=MyIsError(A1)"; worksheet.Range["B2"].Formula = "=MyIsError(A2)"; //Range["B1"]'s value is true. var resultB1 = worksheet.Range["B1"].Value; //Range["B2"]'s value is false. var resultB2 = worksheet.Range["B2"].Value; /* Implementation of MyIsErrorFunctionX public class MyIsErrorFunctionX : CustomFunction { public MyIsErrorFunctionX() : base("MyIsError", FunctionValueType.Boolean, new Parameter[] { new Parameter(FunctionValueType.Variant) }) { } public override object Evaluate(object[] arguments, ICalcContext context) { if (arguments[0] is CalcError) { if ((CalcError)arguments[0] != CalcError.None && (CalcError)arguments[0] != CalcError.GettingData) { return true; } else { return false; } } return false; } } */
' Create a new Workbook Dim workbook As New Workbook Excel.Workbook.AddCustomFunction(New MyIsErrorFunctionX) Dim worksheet As IWorksheet = workbook.Worksheets(0) worksheet.Range!A1.Value = CalcError.Num worksheet.Range!A2.Value = 100 worksheet.Range!B1.Formula = "=MyIsError(A1)" worksheet.Range!B2.Formula = "=MyIsError(A2)" ' Range!B1.Value = True. Dim resultB1 = worksheet.Range!B1.Value ' Range!B2.Value = False. Dim resultB2 = worksheet.Range!B2.Value ' Implementation of MyIsErrorFunctionX ' ' Public Class MyIsErrorFunctionX ' Inherits CustomFunction ' Public Sub New() ' MyBase.New("MyIsError", FunctionValueType.Boolean, {New Parameter(FunctionValueType.Variant)}) ' End Sub ' Public Overrides Function Evaluate(arguments As Object(), context As ICalcContext) As Object ' If TypeOf arguments(0) Is CalcError Then ' Dim calcError = DirectCast(arguments(0), CalcError) ' Return calcError <> CalcError.None AndAlso ' calcError <> CalcError.GettingData ' End If ' Return False ' End Function ' End Class '