Skip to content

Commit bbe26c2

Browse files
authored
Merge pull request #798 from OfficeDev/main
[admin] Publish
2 parents 85c9923 + 86012d4 commit bbe26c2

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

docs/develop/user-input.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
---
22
title: Get user input for scripts
33
description: Add parameters to Office Scripts so users can control their experience.
4-
ms.date: 09/14/2023
4+
ms.date: 08/22/2025
55
ms.localizationpriority: medium
66
---
77

88
# Get user input for scripts
99

10-
Adding parameters to your script lets other users provide data for the script, without needing to edit code. When your script is run through the ribbon or a button, a prompt pops up that asks for input.
10+
Adding parameters to your script lets other users provide data for the script, without needing to edit code. When your script is run through the ribbon or a button, a prompt pops up that asks the user for input, such as an array or a workbook.
1111

1212
:::image type="content" source="../images/user-input-example.png" alt-text="The dialog box shown to users when a script with parameters is run.":::
1313

14-
> [!IMPORTANT]
15-
> Currently, only Excel on the web users will be prompted to enter data for parameterized scripts. Power Automate flows also support giving data to scripts through parameters.
16-
17-
## Example - Highlight large values
14+
## Example scenario: Highlight large values
1815

1916
The following example shows a script that takes a number and string from the user. To test it, open an empty workbook and enter some numbers into several cells.
2017

@@ -49,6 +46,20 @@ function main(
4946

5047
All script input is specified as additional parameters for the `main` function. New parameters are added after the mandatory `workbook: ExcelScript.Workbook` parameter. For example, if you wanted a script to accept a `string` that represents a name as input, you would change the `main` signature to `function main(workbook: ExcelScript.Workbook, name: string)`.
5148

49+
To allow users to import a workbook with a parameterized script, use a two-dimensional array for each parameter that accepts a workbook. The parameter can be of type `string` or `number`. The following example shows how to create a script that accepts workbook imports for both parameters.
50+
51+
```TypeScript
52+
/**
53+
* This script generates a monthly sales report.​
54+
* @param productData The product data for this month.
55+
* @param salesData The sales data for this month.​
56+
*/
57+
function main(workbook: ExcelScript.Workbook, productData: string[][], salesData: string[][]) {
58+
// Code to process data goes here.
59+
// Both the `productData` and `salesData` parameters accept workbook imports.
60+
}​
61+
```
62+
5263
### Optional parameters
5364

5465
Optional parameters don't need the user to provide a value. This implies your script either has default behavior or this parameter is only needed in a corner case. They're denoted in your script with the [optional modifier](https://www.typescriptlang.org/docs/handbook/2/functions.html#optional-parameters) `?`. For example, in `function main(workbook: ExcelScript.Workbook, Name?: string)` the parameter `Name` is optional.

0 commit comments

Comments
 (0)