Skip to content

Commit c552c24

Browse files
authored
Merge pull request #653 from OfficeDev/main
[admin] Publish
2 parents 346bddc + 0fb210e commit c552c24

File tree

7 files changed

+95
-15
lines changed

7 files changed

+95
-15
lines changed

docs/develop/power-automate-integration.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Run Office Scripts with Power Automate
33
description: How to get Office Scripts for Excel working with a Power Automate workflow.
44
ms.topic: integration
5-
ms.date: 08/10/2023
5+
ms.date: 09/19/2023
66
ms.localizationpriority: medium
77
---
88

@@ -42,8 +42,11 @@ This opens a task pane with several options to begin connecting your Office Scri
4242
> [!NOTE]
4343
> The **Run script** Power Automate action only supports scripts stored in your OneDrive. To run scripts shared in SharePoint libraries, use the **Run script from SharePoint library (Preview)** action. This action is currently in preview and is subject to change based on feedback. If you encounter any issues with this action, please report them through the **Help** > **Give Feedback** option in Power Automate.
4444
45-
> [!IMPORTANT]
46-
> The "Run script" action gives people who use the Excel connector significant access to your workbook and its data. Additionally, there are security risks with scripts that make external API calls, as explained in [External calls from Power Automate](external-calls.md). If your admin is concerned with the exposure of highly sensitive data, they can either turn off the Excel Online connector or restrict access to Office Scripts through the [Office Scripts administrator controls](/microsoft-365/admin/manage/manage-office-scripts-settings).
45+
### Data security in Office Scripts with Power Automate
46+
47+
The "Run script" action gives people who use the Excel connector significant access to your workbook and its data. Additionally, there are security risks with scripts that make external API calls, as explained in [External calls from Power Automate](external-calls.md). If your admin is concerned with the exposure of highly sensitive data, they can either turn off the Excel Online connector or restrict access to Office Scripts through the [Office Scripts administrator controls](/microsoft-365/admin/manage/manage-office-scripts-settings).
48+
49+
For admins who have enabled Conditional Access policies for unmanaged devices in their tenant, it's a best practice to disable Power Automate on unmanaged devices. This process is detailed in the blog post [Control Access to Power Apps and Power Automate with Azure AD Conditional Access Policies](https://devblogs.microsoft.com/premier-developer/control-access-to-power-apps-and-power-automate-with-azure-ad-conditional-access-policies/).
4750

4851
## Data transfer in flows for scripts
4952

docs/images/data-validation-error.png

16.4 KB
Loading
5.54 KB
Loading

docs/resources/samples/data-validation-samples.md

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
---
2-
title: Create a dropdown list using data validation
2+
title: "Data validation: dropdown lists, prompts, and warning pop-ups"
33
description: Learn how to add data validation to a cell and give the user a selection of values to enter.
4-
ms.date: 09/08/2023
4+
ms.date: 09/20/2023
55
ms.localizationpriority: medium
66
---
77

8-
# Create a dropdown list using data validation
8+
# Data validation: dropdown lists, prompts, and warning pop-ups
99

10-
This script creates a dropdown selection list for a cell. It uses the existing values of the selected range as the choices for the list.
10+
Data validation helps the user ensure consistency in a worksheet. Use these features to limit what can be entered into a cell and provide warnings or errors to users when those conditions aren't met. To learn more about data validation in Excel, see [Apply data validation to cells](https://support.microsoft.com/office/29fecbcc-d1b9-42c1-9d76-eff3ce5f7249).
11+
12+
## Create a dropdown list using data validation
13+
14+
The following sample creates a dropdown selection list for a cell. It uses the existing values of the selected range as the choices for the list.
1115

1216
:::image type="content" source="../../images/sample-data-validation.png" alt-text="A worksheet showing a range of three cells containing color choices 'red, blue, green' and next to it, the same choices shown in a dropdown list.":::
1317

1418
```TypeScript
1519
function main(workbook: ExcelScript.Workbook) {
1620
// Get the values for data validation.
17-
let selectedRange = workbook.getSelectedRange();
18-
let rangeValues = selectedRange.getValues();
21+
const selectedRange = workbook.getSelectedRange();
22+
const rangeValues = selectedRange.getValues();
1923

2024
// Convert the values into a comma-delimited string.
2125
let dataValidationListString = "";
@@ -29,8 +33,8 @@ function main(workbook: ExcelScript.Workbook) {
2933
selectedRange.clear(ExcelScript.ClearApplyTo.contents);
3034

3135
// Apply the data validation to the first cell in the selected range.
32-
let targetCell = selectedRange.getCell(0,0);
33-
let dataValidation = targetCell.getDataValidation();
36+
const targetCell = selectedRange.getCell(0,0);
37+
const dataValidation = targetCell.getDataValidation();
3438

3539
// Set the content of the dropdown list.
3640
dataValidation.setRule({
@@ -41,3 +45,72 @@ function main(workbook: ExcelScript.Workbook) {
4145
});
4246
}
4347
```
48+
49+
## Add a prompt to a range
50+
51+
This example creates a prompt note that appears when a user enters the given cells. This is used to remind users about input requirements, without strict enforcement.
52+
53+
:::image type="content" source="../../images/data-validation-prompt.png" alt-text="A prompt with the title 'First names only' and the message 'Only enter the first name of the employee, not the full name.' next to a worksheet with some names in cells.":::
54+
55+
```TypeScript
56+
/**
57+
* This script creates a text prompt that's shown in C2:C8 when a user enters the cell.
58+
*/
59+
function main(workbook: ExcelScript.Workbook) {
60+
// Get the data validation object for C2:C8 in the current worksheet.
61+
const selectedSheet = workbook.getActiveWorksheet();
62+
const dataValidation = selectedSheet.getRange("C2:C8").getDataValidation();
63+
64+
// Clear any previous validation to avoid conflicts.
65+
dataValidation.clear();
66+
67+
// Create a prompt to remind users to only enter first names in this column.
68+
const prompt: ExcelScript.DataValidationPrompt = {
69+
showPrompt: true,
70+
title: "First names only",
71+
message: "Only enter the first name of the employee, not the full name."
72+
}
73+
dataValidation.setPrompt(prompt);
74+
}
75+
```
76+
77+
## Alert the user when invalid data is entered
78+
79+
The following sample script prevents the user from entering anything other than positive numbers into a range. If they try to put anything else, an error message pops up and indicates the problem.
80+
81+
:::image type="content" source="../../images/data-validation-error.png" alt-text="An error message with the title 'Invalid data' and the message 'Positive numbers only.' next to a cell with a negative number.":::
82+
83+
```TypeScript
84+
/**
85+
* This script creates a data validation rule for the range B2:B5.
86+
* All values in that range must be a positive number.
87+
* Attempts to enter other values are blocked and an error message appears.
88+
*/
89+
function main(workbook: ExcelScript.Workbook) {
90+
// Get the range B2:B5 in the active worksheet.
91+
const currentSheet = workbook.getActiveWorksheet();
92+
const positiveNumberOnlyCells = currentSheet.getRange("B2:B5");
93+
94+
// Create a data validation rule to only allow positive numbers.
95+
const positiveNumberValidation: ExcelScript.BasicDataValidation = {
96+
formula1: "0",
97+
operator: ExcelScript.DataValidationOperator.greaterThan
98+
};
99+
const positiveNumberOnlyRule: ExcelScript.DataValidationRule = {
100+
wholeNumber: positiveNumberValidation
101+
};
102+
103+
// Set the rule on the range.
104+
const rangeDataValidation = positiveNumberOnlyCells.getDataValidation();
105+
rangeDataValidation.setRule(positiveNumberOnlyRule);
106+
107+
// Create an alert to appear when data other than positive numbers are entered.
108+
const positiveNumberOnlyAlert: ExcelScript.DataValidationErrorAlert = {
109+
message: "Positive numbers only.",
110+
showAlert: true,
111+
style: ExcelScript.DataValidationAlertStyle.stop,
112+
title: "Invalid data"
113+
};
114+
rangeDataValidation.setErrorAlert(positiveNumberOnlyAlert);
115+
}
116+
```

docs/resources/samples/samples-overview.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Office Scripts samples
33
description: Available Office Scripts samples and scenarios.
4-
ms.date: 09/08/2023
4+
ms.date: 09/20/2023
55
ms.localizationpriority: medium
66
---
77

@@ -26,6 +26,7 @@ This section contains [Office Scripts](../../overview/excel.md) based solutions
2626
| [Add comments in Excel](add-excel-comments.md) | This sample adds comments to a cell including @mentioning a colleague. |
2727
| [Add images to a workbook](add-image-to-workbook.md) | This sample adds an image to a workbook and copies an image across sheets.|
2828
| [Copy multiple Excel tables into a single table](copy-tables-combine.md) | This sample combines data from multiple Excel tables into a single table that includes all the rows. |
29+
| [Data validation: dropdown lists, prompts, and warning pop-ups](data-validation-samples.md) | These samples show how to use data validation to mandate specific conditions for cell data and how the user is alerted to these rules. |
2930
| [Create a workbook table of contents](table-of-contents.md) | This sample creates a table of contents with links to each worksheet. |
3031
| [JavaScript `Date` samples](javascript-dates.md) | A collection of samples that show how to translate between JavaScript and Excel date formats. |
3132
| [Record day-to-day changes in Excel and report them with a Power Automate flow](report-day-to-day-changes.md) | This sample uses a scheduled Power Automate flow to record daily readings and report the changes. |

docs/testing/platform-limits.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Platform limits and requirements with Office Scripts
33
description: Resource limits and browser support for Office Scripts when used with Excel.
44
ms.topic: limits-and-quotas
5-
ms.date: 09/08/2023
5+
ms.date: 09/19/2023
66
ms.localizationpriority: medium
77
---
88

@@ -78,13 +78,16 @@ Your browser needs third-party cookies enabled to show the **Automate** tab in E
7878

7979
## Conditional Access
8080

81-
[Conditional Access](/azure/active-directory/conditional-access/overview) policies can restrict access to SharePoint and OneDrive for [unmanaged devices](/sharepoint/control-access-from-unmanaged-devices). If your device isn't managed by the tenant, you may not have access to specific scripts, or may only be able to access them through the browser.
81+
[Conditional Access](/azure/active-directory/conditional-access/overview) policies restrict access to SharePoint and OneDrive for [unmanaged devices](/sharepoint/control-access-from-unmanaged-devices). If your device isn't managed by the tenant, you may not have access to specific scripts, or may only be able to access them through the browser.
8282

8383
If you script is blocked by Conditional Access policies, you'll receive one of two error messages. These messages also surface in Power Automate if your flow is run from an unmanaged device.
8484

8585
- "Due to organizational policies, you can’t access this resource from this untrusted device."
8686
- "We can't find this script. It may have been deleted by another user." (If your version of Excel is older.)
8787

88+
> [!IMPORTANT]
89+
> Administrators should consider blocking all access to Power Automate from unmanaged devices. This process is detailed in the blog post [Control Access to Power Apps and Power Automate with Azure AD Conditional Access Policies](https://devblogs.microsoft.com/premier-developer/control-access-to-power-apps-and-power-automate-with-azure-ad-conditional-access-policies/).
90+
8891
## API support on older Excel versions
8992

9093
Some Office Scripts APIs may not be supported by Excel for Windows or Excel for Mac, especially older builds. These include newer APIs and APIs for web-only features. If a script contains unsupported APIs, the Code Editor displays a warning. If you try to run such a script, it won't run. Instead, the **Script Run Status** task pane displays a warning message that says, "This script currently must be run on Excel for the web. Open the workbook in the browser then try again, or contact the script owner for help."

docs/toc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ items:
7878
href: resources/samples/add-image-to-workbook.md
7979
- name: Copy multiple tables into single table
8080
href: resources/samples/copy-tables-combine.md
81-
- name: Create a drop-down list using data validation
81+
- name: "Data validation: dropdown lists, prompts, and warning pop-ups"
8282
href: resources/samples/data-validation-samples.md
8383
- name: Create a workbook table of contents
8484
href: resources/samples/table-of-contents.md

0 commit comments

Comments
 (0)