Redigera

Dela via


Custom functions naming and localization

This article provides guidelines and best practices for naming custom functions and explains how to localize them.

Custom functions naming guidelines

A custom function is identified by an id and a name in the JSON metadata.

  • id: Unique identifier used in code.
  • name: Display name shown to users. It can be localized.

Important

Note that Excel custom functions are available on the following platforms.

  • Office on the web
  • Office on Windows
    • Microsoft 365 subscription
    • retail perpetual Office 2016 and later
    • volume-licensed perpetual/LTSC Office 2021 and later
  • Office on Mac

Excel custom functions aren't currently supported in the following:

  • Office on iPad
  • volume-licensed perpetual versions of Office 2019 or earlier on Windows

Note

The unified manifest for Microsoft 365 doesn't currently support custom functions projects. You must use the add-in only manifest for custom functions projects. For more information, see Office Add-ins manifest.

A function name can differ from the id for localization. If you don't need localization, it's best to use the same value for both.

A function's name and id share some similar rules.

  • Both must start with a letter and be at least three characters.
  • id: Only A–Z, 0–9, underscore, and period characters are allowed.
  • name: Any Unicode alphabetic characters, underscore, and period characters are allowed.

Excel displays built-in function names in uppercase letters (for example, SUM). Use uppercase for your custom functions to help them blend in naturally.

Avoid names that match:

Naming conflicts

If your function name conflicts with one from another add-in, Excel shows the #REF! error.

Fix conflicts by renaming your function or uninstalling the other add-in. For testing in multiple environments, use a short namespace prefix (such as ADDINNAME_FUNCTIONNAME).

Best practices

  • Use extra function arguments instead of creating multiple similar function names. For example, GETNAME(firstName, middleName, lastName) is more efficient than having separate functions like GETFIRSTNAME, GETMIDDLENAME, and GETLASTNAME.
  • Avoid abbreviations that aren’t clear. For example, INCREASETIME is easier to understand than INC.
  • Choose action verbs for function names. Use GETZIPCODE instead of just ZIPCODE.
  • Be consistent. Use the same verb for similar actions, such as DELETEZIPCODE and DELETEADDRESS.
  • For streaming functions, add STREAM to the name or include a note in the description.
  • Use a short vendor prefix in your function names to avoid conflicts with other add-ins. For example, use CONTOSO_GETPRICE or CONTOSO_TAX_CALC.

Tip

If you'll be testing your add-in across multiple environments (for example, in development, staging, demo, etc.), we recommend that you maintain a different manifest file for each environment. In each manifest file, you can:

  • Specify the URLs that correspond to the environment.

  • Customize metadata values so that end users are able to identify a sideloaded add-in's corresponding environment. For example:

    • In the unified manifest for Microsoft 365, customize the "name" property of the add-in and the "label" properties for various UI controls to indicate the environment.
    • In the add-in only manifest, customize the DisplayName element and and labels within the Resources element to indicate the environment.
  • Customize the custom functions namespace to indicate the environment, if your add-in defines custom functions.

By following this guidance, you'll streamline the testing process and avoid issues that would otherwise occur when an add-in is simultaneously sideloaded for multiple environments.

Naming constraints quick reference

Guideline id name Notes
Allowed characters A–Z 0–9 _ . Unicode alphabetic characters _ . Keep id simple. Localize name.
Must start with a letter Yes Yes Avoids cell reference confusion.
Minimum length 3 3 Short names reduce clarity.
Capitalization All uppercase recommended All uppercase recommended Matches Excel style.
Localizable No Yes Keep id stable. Localize name as needed.
Can mimic cell address No No Prevent address parsing errors.
Reserved macro names Disallowed Disallowed Some examples: RUN, ECHO.

Localize custom functions

You can localize both your add-in and your custom function names. Add localized function names in your JSON file and set locale overrides in the add-in only manifest.

Important

Autogenerated metadata doesn't work for localization so you need to update the JSON file manually. To learn how to do this, see Manually create JSON metadata for custom functions.

Localize function names

To localize your custom functions, create a separate JSON metadata file for each language. In each file, add the name and description properties in the target language. Use functions.json for English and include the locale in the filename for other languages, such as functions-de.json for German.

Excel only localizes the name and description properties. The id is not localized and should remain unchanged after it's set.

Important

Avoid an id or name that matches a built-in Excel function in any language.

The following JSON shows how to define a function with the id property "MULTIPLY". The name and description property of the function is localized for German. Each parameter name and description is also localized for German.

{
    "id": "MULTIPLY",
    "name": "SUMME",
    "description": "Summe zwei Zahlen",
    "helpUrl": "http://www.contoso.com",
    "result": {
        "type": "number",
        "dimensionality": "scalar"
    },
    "parameters": [
        {
            "name": "eins",
            "description": "Erste Nummer",
            "dimensionality": "scalar"
        },
        {
            "name": "zwei",
            "description": "Zweite Nummer",
            "dimensionality": "scalar"
        }
    ]
}

Compare the previous JSON with the following JSON for English.

{
    "id": "MULTIPLY",
    "name": "MULTIPLY",
    "description": "Multiplies two numbers",
    "helpUrl": "http://www.contoso.com",
    "result": {
        "type": "number",
        "dimensionality": "scalar"
    },
    "parameters": [
        {
            "name": "one",
            "description": "first number",
            "dimensionality": "scalar"
        },
        {
            "name": "two",
            "description": "second number",
            "dimensionality": "scalar"
        }
    ]
}

Localize your add-in

After you create a JSON for each language, add an override to your add-in only manifest that points to the correct file. The following manifest XML shows a default en-us locale plus an override JSON file URL for de-de (Germany).

<DefaultLocale>en-us</DefaultLocale>
...
<Resources>
     <bt:Urls>
        <bt:Url id="Contoso.Functions.Metadata.Url" DefaultValue="https://localhost:3000/dist/functions.json"/>
          <bt:Override Locale="de-de" Value="https://localhost:3000/dist/functions-de.json" />
        </bt:url>
        
     </bt:Urls>
</Resources>

For more information on the process of localizing an add-in, see Localization for Office Add-ins.

Next steps

Learn about error handling best practices.

See also