REFERENCE
U.COMPILE
Summary
Creates a user-defined function written in C# or Python that can be called with U.INVOKE, by using the invoke() column function in U functions that support it (U.VAGGREGATE, U.TABLE_TO_GRID and U.REPLACE) or by using Invoke(
Syntax
=U.COMPILE(function_name, code, [parameters], [imports], [references], [compiler_switches], [settings], [classes], [menu_entry])
Parameters
| Parameter | Required | Description |
|---|---|---|
function_name |
Yes | The name of the function to be created. Must be a valid function name in C#/Python |
code |
Yes | The C# or Python code. If set to "CLEAR" then the specified function will be removed if it exists |
[parameters] |
No | The names, types descriptions and default values of any parameters. Up to 20 parameters supported. Parameter names cannot start with "U_", "U.", "RUNLINE." or "RUNLINE_" and the parameter name "invoke_config" is reserved |
[imports] |
No | The namespaces to be imported when compiling the method. These are what appear after the "using" keyword at the top of the generated code file. The following are always added so do not need to be specified: System, System.Linq, System.Text, System.Threading, System.Threading.Tasks, System.Collections, System.Collections.Generic, System.Collections.Concurrent |
[references] |
No | The names of system code libraries, or paths to non-system code libraries, to be referenced during compilation. The following system libraries are referenced by default so do not need to be specified: System.dll, System.Core.dll |
[compiler_switches] |
No | Compiler switches passed as command line parameters to compiler. The switches langversion:5 and optimize are included by default |
[settings] |
No | Flags and key/value pairs that impact various aspects of compilation and invocation |
[classes] |
No | Code for supporting classes/code. Must not include using statements, which should be provided in the imports parameter |
[menu_entry] |
No | A table of menu entry details; see documentation of U.MENU for details. When provided, specified menu entries appear in Excel's ribbon menu upon compilation of the function. Specified menu entries are also added when users receive the function as a distribution |
Behavior
The documented public interface is supported by the current U Add-in source signature and the maintained Usage Examples workbook. Optional parameters are shown in square brackets in the syntax above; omit the brackets when entering a formula.
Return Value
Returns the function result or action status described by the formula and parameters above. The maintained sources do not define a narrower, stable return contract for this function.
Examples
Notes
- Formula examples are preserved from maintained workbook usage and normalized to the current
U.prefix. - Complete formulas demonstrate working patterns; they do not imply that undocumented option values are supported.
- Where maintained sources do not specify every accepted value, default, or error message, this page does not infer one.
- For functions that perform actions, use a visible trigger or supported block/throttle parameter to avoid unintended repetition during recalculation.
Related
- Concept: Compiled and Invoked Functions
- Concept: Workbook Automation
- How-to: Run a Click-Driven Script