Custom Formula in WPF Spreadsheet (SfSpreadsheet)

SfSpreadsheet allows you to add custom formulas into its function library. You can add the custom formula into the SfSpreadsheet by using the AddFunction method of FormulaEngine,

spreadsheet.WorkbookLoaded += spreadsheet_WorkbookLoaded;

void spreadsheet_WorkbookLoaded(object sender, WorkbookLoadedEventArgs args)

    foreach (var grid in args.GridCollection)
  //Computing the formula at runtime

   var range = spreadsheet.ActiveSheet.Range["B2"];

private void AddCustomFormula(SpreadsheetGrid grid)

  // Add a formula named Find to the Library.
   grid.FormulaEngine.AddFunction("Find", new FormulaEngine.LibraryFunction(ComputeLength));      

//Implementation of formula
public string ComputeLength(string range)
  //Used to calculate the length of the string
    return range.Length.ToString();