Custom Formula in WPF Spreadsheet (SfSpreadsheet)

28 Jul 20211 minute to read

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();


You can refer to our WPF Spreadsheet feature tour page for its groundbreaking feature representations. You can also explore our WPF Spreadsheet example to know how to render and configure the spreadsheet.