The DevExpress ASP.NET MVC Spreadsheet provides the capability to create your own custom functions. Custom functions are available for spreadsheet calculations and can be used in cell formulas in the same manner as built-in functions. A custom function executes a server custom code that performs the required calculation and returns the result.
Custom functions supported by the Spreadsheet are global - they can be accessed from all spreadsheet documents opened on the server. To create a custom function, implement the CustomFunction interface and register the function using the RegisterGlobalCustomFunction static method. It is recommended to register custom functions only once at the application level. The following demo code illustrates how this can be done in the Global.asax file's Application_Start method.
void Application_Start(object sender, EventArgs e) {
...
ASPxSpreadsheet.RegisterGlobalCustomFunction(new DiscountFunction());
...
}
In this demo, the DiscountFunction custom function is defined. It is used in the C7 cell to calculate a discount based on the order's Quantity (C5) and Unit Price (C4) values. In the calculation, different discount rates are used depending on the total number of items in the order.
See Also:
Local Copy of this Demo To inspect the source code for this demo on your machine, you must first install our components via the DevExpress Component Installer. |
You can open a local copy of this online demo directly from this webpage (if using v20.2.8, 21.1.4 or higher).
\Users\Public\Documents\DevExpress Demos XX.X\Components\ASP.NET\CS\MVCxSpreadsheetDemos |