Custom Formula in UWP Spreadsheet (SfSpreadsheet)

10 May 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 = spreadsheetControl.ActiveSheet.Range["B2"];

private void AddCustomFormula(SpreadsheetGrid grid)

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

//Implementation of formula
public string ComputeLength(string range)

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