Skip to content

Commit 52c85b8

Browse files
authored
[Excel] (Custom functions) Add new cell value type JSON parameter (#4632)
* [Excel] (Custom functions) Add new cell value type JSON parameter * [Excel] (Custom functions) Add new cell value type JSON parameter * Add closing code ticks * Add cell value type values * Minor adjustments * Clarify new cell value type rules * Grammar changes * Remove FormattedNumberCellValue from recommended * Linter suggestion
1 parent 687de5a commit 52c85b8

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

docs/excel/custom-functions-data-types-concepts.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Custom functions and data types
33
description: Use Excel data types with your custom functions and Office Add-ins.
4-
ms.date: 10/17/2022
4+
ms.date: 06/15/2025
55
ms.topic: overview
66
ms.custom: scenarios:getting-started
77
ms.localizationpriority: medium
@@ -57,7 +57,7 @@ The following code sample shows a custom function that takes an [EntityCellValue
5757
/**
5858
* Accept an entity value data type as a function input.
5959
* @customfunction
60-
* @param {any} value
60+
* @param {Excel.EntityCellValue} value
6161
* @param {string} attribute
6262
* @returns {any} The text value of the entity.
6363
*/

docs/excel/custom-functions-json-autogeneration.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Autogenerate JSON metadata for custom functions
33
description: Use JSDoc tags to dynamically create your custom functions JSON metadata.
4-
ms.date: 07/11/2023
4+
ms.date: 06/15/2025
55
ms.localizationpriority: medium
66
---
77

@@ -34,7 +34,7 @@ The plugin is [CustomFunctionsMetadataPlugin](https://github.com/OfficeDev/Offic
3434

3535
### Multiple custom function source files
3636

37-
If, and only if, you have organized your custom functions into multiple source files, there are additional steps.
37+
If, and only if, you have organized your custom functions into multiple source files, there are additional steps.
3838

3939
1. In the webpack.config.js file, replace the string value of `input` with an array of string URLs that point to each of the files. The following is an example:
4040

@@ -395,6 +395,22 @@ By specifying a parameter type, Excel will convert values into that type before
395395

396396
A single value may be represented using one of the following types: `boolean`, `number`, `string`.
397397

398+
### Cell value type
399+
400+
Use the `type` subfield `cellValueType` to specify that a custom function accept and return Excel data types. The `type` value must be `any` to use the `cellValueType` subfield. Accepted `cellValueType` values are:
401+
402+
- `Excel.CellValue`
403+
- `Excel.BooleanCellValue`
404+
- `Excel.DoubleCellValue`
405+
- `Excel.EntityCellValue`
406+
- `Excel.ErrorCellValue`
407+
- `Excel.LinkedEntityCellValue`
408+
- `Excel.LocalImageCellValue`
409+
- `Excel.StringCellValue`
410+
- `Excel.WebImageCellValue`
411+
412+
For a code sample using the `Excel.EntityCellValue` type, see [Input an entity value](custom-functions-data-types-concepts.md#input-an-entity-value).
413+
398414
### Matrix type
399415

400416
Use a two-dimensional array type to have the parameter or return value be a matrix of values. For example, the type `number[][]` indicates a matrix of numbers and `string[][]` indicates a matrix of strings.

docs/excel/custom-functions-json.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Manually create JSON metadata for custom functions in Excel
33
description: Define JSON metadata for custom functions in Excel and associate your function ID and name properties.
4-
ms.date: 10/10/2022
4+
ms.date: 06/15/2025
55
ms.localizationpriority: medium
66
---
77

@@ -142,6 +142,8 @@ The `allowCustomDataForDataTypeAny` property is a boolean data type. Setting thi
142142
> [!NOTE]
143143
> Unlike most of the other JSON metadata properties, `allowCustomDataForDataTypeAny` is a top-level property and contains no sub-properties. See the preceding [JSON metadata code sample](#json-metadata-example) for an example of how to format this property.
144144
145+
If your custom function uses the `cellValueType` [parameter](#parameters), then setting the `allowCustomDataForDataTypeAny` isn't required to accept data types as parameters and return values.
146+
145147
### allowErrorForDataTypeAny
146148

147149
The `allowErrorForDataTypeAny` property is a boolean data type. Setting the value to `true` allows a custom function to process errors as input values. All parameters with the type `any` or `any[][]` can accept errors as input values when `allowErrorForDataTypeAny` is set to `true`. The default `allowErrorForDataTypeAny` value is `false`.
@@ -185,9 +187,24 @@ The `parameters` property is an array of parameter objects. The following table
185187
| `dimensionality` | string | No | Must be either `scalar` (a non-array value) or `matrix` (a 2-dimensional array). |
186188
| `name` | string | Yes | The name of the parameter. This name is displayed in Excel's IntelliSense. |
187189
| `type` | string | No | The data type of the parameter. Can be `boolean`, `number`, `string`, or `any`, which allows you to use of any of the previous three types. If this property is not specified, the data type defaults to `any`. |
190+
| `cellValueType` | string | No | A subfield of the `type` property. Specifies the Excel data types accepted by the custom function. Accepts the case-insensitive values `cellvalue`, `booleancellvalue`, `doublecellvalue`, `entitycellvalue`, `errorcellvalue`, `linkedentitycellvalue`, `localimagecellvalue`, `stringcellvalue`, and `webimagecellvalue`. <br/><br/>The `type` field must have the value `any` to use the `cellValueType` subfield. |
188191
| `optional` | boolean | No | If `true`, the parameter is optional. |
189192
|`repeating`| boolean | No | If `true`, parameters populate from a specified array. Note that functions all repeating parameters are considered optional parameters by definition. |
190193

194+
> [!TIP]
195+
> See the following code snippet for an example of how to format the `cellValueType` parameter in JSON metadata.
196+
>
197+
> ```json
198+
> "parameters": [
199+
> {
200+
> "name": "range",
201+
> "description": "the input range",
202+
> "type": "any",
203+
> "cellValueType": "webimagecellvalue"
204+
> }
205+
> ]
206+
> ```
207+
191208
### result
192209
193210
The `result` object defines the type of information that is returned by the function. The following table lists the properties of the `result` object.

0 commit comments

Comments
 (0)