Skip to content

Commit 772144d

Browse files
authored
Merge pull request #647 from OfficeDev/main
[admin] Publish
2 parents ac35a31 + dc39577 commit 772144d

File tree

8 files changed

+122
-14
lines changed

8 files changed

+122
-14
lines changed

docs/develop/user-input.md

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

@@ -12,7 +12,7 @@ Adding parameters to your script lets other users provide data for the script, w
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

1414
> [!IMPORTANT]
15-
> Currently, only select users in preview will be prompted to enter data for parameterized scripts in Excel on the web. Power Automate flows also support giving data to scripts through parameters.
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.
1616
1717
## Example - Highlight large values
1818

@@ -113,3 +113,4 @@ When adding input parameters and return values, consider the following allowance
113113

114114
- [Pass data to and from scripts in Power Automate](power-automate-parameters-returns.md)
115115
- [Run Office Scripts in Excel with buttons](script-buttons.md)
116+
- [Set conditional formatting for cross-column comparisons](../resources/samples/conditional-formatting-parameters.md)

docs/overview/script-storage.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Office Scripts file storage and ownership
33
description: Information about how Office Scripts are stored in Microsoft OneDrive and transferred between owners.
4-
ms.date: 08/29/2023
4+
ms.date: 09/08/2023
55
ms.localizationpriority: medium
66
---
77

@@ -11,6 +11,9 @@ Office Scripts are stored as **.osts** files in your Microsoft OneDrive or a Sha
1111

1212
Excel only recognizes and runs a script if it's in your OneDrive folder, a Sharepoint folder, or shared with the workbook. This means Excel needs internet connectivity to access Office Scripts.
1313

14+
> [!NOTE]
15+
> Admin settings for Conditional Access in OneDrive and SharePoint affect Office Scripts. For more information, see the [Conditional Access section of Platform limits and requirements with Office Scripts](../testing/platform-limits.md#conditional-access).
16+
1417
## OneDrive
1518

1619
The default behavior is that Office Scripts are stored in your OneDrive. The **.osts** files are found in the **/Documents/Office Scripts/** folder. Any edits made to these **.osts** files, such as renaming or deleting files, will be reflected in the Code Editor and Script Gallery.
@@ -37,7 +40,7 @@ To save a copy of a script to SharePoint, go to the **More options (…)** menu
3740
3841
## Restore deleted scripts
3942

40-
When you delete a script in Excel, it goes to your OneDrive or SharePoint recycle bin. To restore a deleted script, follow the steps listed in [How to recover missing, deleted or corrupted items in SharePoint and OneDrive for work or school](https://support.microsoft.com/office/how-to-recover-missing-deleted-or-corrupted-items-in-sharepoint-and-onedrive-for-work-or-school-3d748edf-c072-46c9-81a4-4989056ebc87). Restoring an **.osts** file returns it to the **All scripts** list.
43+
When you delete a script in Excel, it goes to your OneDrive or SharePoint recycle bin. To restore a deleted script, follow the steps listed in [How to recover missing, deleted or corrupted items in SharePoint and OneDrive for work or school](https://support.microsoft.com/office/3d748edf-c072-46c9-81a4-4989056ebc87). Restoring an **.osts** file returns it to the **All scripts** list.
4144

4245
A deleted script is unshared with the workbook. When you restore a script, it does **not** retain its script access. You will need to share the script again.
4346

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
title: Set conditional formatting for cross-column comparisons
3+
description: Learn how to apply conditional formatting and get input from the user.
4+
ms.date: 09/07/2023
5+
ms.localizationpriority: medium
6+
---
7+
8+
# Set conditional formatting for cross-column comparisons
9+
10+
This sample shows how to apply conditional formatting to a range. The conditions used are comparing values to those in an adjacent column. Additionally, this sample uses [parameters to get user input](../../develop/user-input.md). This lets the person running the script select the range, the type of comparison, and the colors.
11+
12+
## Sample code: Set conditional formatting
13+
14+
```TypeScript
15+
/**
16+
* Formats a range on the current sheet based on values in an adjacent column.
17+
* @param rangeAddress The A1-notation range to format.
18+
* @param compareTo The adjacent column to compare against.
19+
* @param colorIfGreater The color of the cell if the value is greater than the adjacent column.
20+
* @param colorIfEqual The color of the cell if the value is equal to the adjacent column.
21+
* @param colorIfLess The color of the cell if the value is less than the adjacent column.
22+
*/
23+
function main(
24+
workbook: ExcelScript.Workbook,
25+
rangeAddress: string, compareTo: "Left" | "Right",
26+
colorIfGreater: "Red" | "Green" | "Yellow" | "None",
27+
colorIfLess: "Red" | "Green" | "Yellow" | "None",
28+
colorIfEqual: "Red" | "Green" | "Yellow" | "None"
29+
) {
30+
// Get the specified range.
31+
const selectedSheet = workbook.getActiveWorksheet();
32+
const range = selectedSheet.getRange(rangeAddress);
33+
34+
// Remove old conditional formatting.
35+
range.clearAllConditionalFormats();
36+
37+
// Get the address of the first adjacent cell of the adjacent column.
38+
let adjacentColumn: string;
39+
if (compareTo == "Left") {
40+
adjacentColumn = range.getColumnsBefore().getCell(0, 0).getAddress();
41+
} else {
42+
adjacentColumn = range.getColumnsAfter().getCell(0, 0).getAddress();
43+
}
44+
45+
// Remove the worksheet name from the address to create a relative formula.
46+
let formula = "=$" + adjacentColumn.substring(adjacentColumn.lastIndexOf("!") + 1);
47+
48+
// Set the conditional formatting based on the user's color choices.
49+
setConditionalFormatting(
50+
range.addConditionalFormat(ExcelScript.ConditionalFormatType.cellValue).getCellValue(),
51+
colorIfGreater,
52+
formula,
53+
ExcelScript.ConditionalCellValueOperator.greaterThan);
54+
setConditionalFormatting(
55+
range.addConditionalFormat(ExcelScript.ConditionalFormatType.cellValue).getCellValue(),
56+
colorIfEqual,
57+
formula,
58+
ExcelScript.ConditionalCellValueOperator.equalTo);
59+
setConditionalFormatting(
60+
range.addConditionalFormat(ExcelScript.ConditionalFormatType.cellValue).getCellValue(),
61+
colorIfLess,
62+
formula,
63+
ExcelScript.ConditionalCellValueOperator.lessThan);
64+
}
65+
66+
function setConditionalFormatting(
67+
conditionalFormat: ExcelScript.CellValueConditionalFormat,
68+
color: "Red" | "Green" | "Yellow" | "None",
69+
formula: string,
70+
operator: ExcelScript.ConditionalCellValueOperator
71+
) {
72+
// Pick the fill and font colors based on the preset color choices.
73+
if (color == "Red") {
74+
conditionalFormat.getFormat().getFont().setColor("#9C0006");
75+
conditionalFormat.getFormat().getFill().setColor("#FFC7CE");
76+
} else if (color == "Green") {
77+
conditionalFormat.getFormat().getFont().setColor("#001600");
78+
conditionalFormat.getFormat().getFill().setColor("#C6EFCE");
79+
} else if (color == "Yellow") {
80+
conditionalFormat.getFormat().getFont().setColor("#9C5700");
81+
conditionalFormat.getFormat().getFill().setColor("#FFEB9C");
82+
} else { /* None */
83+
return;
84+
}
85+
86+
// Apply the conditional formatting.
87+
conditionalFormat.setRule({
88+
formula1: formula,
89+
operator: operator
90+
});
91+
}
92+
```

docs/resources/samples/samples-overview.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ This section contains [Office Scripts](../../overview/excel.md) based solutions
3030
| [JavaScript `Date` samples](javascript-dates.md) | A collection of samples that show how to translate between JavaScript and Excel date formats. |
3131
| [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. |
3232
| [Row and column visibility samples](row-and-column-visibility.md) | A collection of samples that demonstrate how to show, hide, and freeze rows and columns. |
33+
| [Set conditional formatting for cross-column comparisons](conditional-formatting-parameters.md) | This sample applies formatting based on values in adjacent columns. It also gets user input through script parameters. |
3334

3435
## Beyond the basics
3536

@@ -42,12 +43,12 @@ Check out the following end-to-end project that automates sample scenarios along
4243
| [Cross-reference workbooks](excel-cross-reference.md) | This sample uses Office Scripts and Power Automate to cross-reference and validate information in different workbooks. |
4344
| [Count blank rows in a specific sheet or in all sheets](count-blank-rows.md) | This sample detects if there are any blank rows in sheets where you anticipate data to be present and then report the blank row count for usage in a Power Automate flow. |
4445
| [Email chart and table images](email-images-chart-table.md) | This sample uses Office Scripts and Power Automate actions to create a chart and send that chart as an image by email. |
45-
| [External fetch calls](external-fetch-calls.md) | This sample uses `fetch` to get information from GitHub for the script. |
4646
| [Manage calculation mode in Excel](excel-calculation.md) | This sample shows how to use the calculation mode and calculate methods in Excel using Office Scripts. |
4747
| [Move rows across tables](move-rows-across-tables.md) | This sample shows how to move rows across tables by saving filters, then processing and reapplying the filters. |
4848
| [Output Excel data as JSON](get-table-data.md) | This solution shows how to output Excel table data as JSON to use in Power Automate. |
4949
| [Remove hyperlinks from each cell in an Excel worksheet](remove-hyperlinks-from-cells.md) | This sample clears all of the hyperlinks from the current worksheet. |
5050
| [Run a script on all Excel files in a folder](automate-tasks-on-all-excel-files-in-folder.md) | This project performs a set of automation tasks on all files situated in a folder on OneDrive for Business (can also be used for a SharePoint folder). It performs calculations on the Excel files, adds formatting, and inserts a comment that @mentions a colleague. |
51+
| [Use external fetch calls](external-fetch-calls.md) | This sample uses `fetch` to get information from GitHub for the script. |
5152
| [Write a large dataset](write-large-dataset.md) | This sample shows how to send a large range as smaller subranges. |
5253

5354
## Scenarios

docs/testing/platform-limits.md

Lines changed: 10 additions & 1 deletion
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: 04/20/2023
5+
ms.date: 09/08/2023
66
ms.localizationpriority: medium
77
---
88

@@ -76,6 +76,15 @@ Your browser needs third-party cookies enabled to show the **Automate** tab in E
7676
- [Firefox](https://support.mozilla.org/kb/disable-third-party-cookies)
7777
- [Safari](https://support.apple.com/guide/safari/manage-cookies-and-website-data-sfri11471/mac)
7878

79+
## Conditional Access
80+
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.
82+
83+
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.
84+
85+
- "Due to organizational policies, you can’t access this resource from this untrusted device."
86+
- "We can't find this script. It may have been deleted by another user." (If your version of Excel is older.)
87+
7988
## API support on older Excel versions
8089

8190
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/testing/power-automate-troubleshooting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: Troubleshoot Office Scripts running in Power Automate
33
description: Tips, platform information, and known issues with the integration between Office Scripts and Power Automate.
44
ms.topic: troubleshooting-general
5-
ms.date: 04/20/2023
5+
ms.date: 09/08/2023
66
ms.localizationpriority: medium
77
---
88

99
# Troubleshoot Office Scripts running in Power Automate
1010

11-
Power Automate lets you take your Office Script automation to the next level. However, because Power Automate runs scripts on your behalf in independent Excel sessions, there are a few important things to note.
11+
Power Automate runs scripts on your behalf in independent Excel sessions. This causes some behavioral changes that may create issues with certain scripts or scenarios. There are also limitations and behaviors from the Power Automate platform script writers should know. Be sure to read the articles [Troubleshoot Office Scripts](troubleshooting.md) and [Platform limits and requirements with Office Scripts](platform-limits.md), as much of that information also applies to scripts in flows.
1212

1313
> [!TIP]
1414
> If you're just starting to use Office Scripts with Power Automate, please start with [Run Office Scripts with Power Automate](../develop/power-automate-integration.md) to learn about the platforms.

docs/testing/troubleshooting.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Troubleshoot Office Scripts
33
description: Debugging tips and techniques for Office Scripts, as well as help resources.
44
ms.topic: troubleshooting-general
5-
ms.date: 02/24/2023
5+
ms.date: 09/08/2023
66
ms.localizationpriority: medium
77
---
88

@@ -13,7 +13,11 @@ As you develop Office Scripts, you may make mistakes. It's okay. You have the to
1313
> [!NOTE]
1414
> For troubleshooting advice specific to Office Scripts with Power Automate, see [Troubleshoot Office Scripts running in Power Automate](power-automate-troubleshooting.md).
1515
16-
## Types of errors
16+
## Platform limits and requirements
17+
18+
For a detailed list of limitations on the Office Scripts platform due to Excel, Power Automate, or other technologies, see [Platform limits and requirements with Office Scripts](platform-limits.md).
19+
20+
## Script errors
1721

1822
Office Scripts errors fall into one of two categories:
1923

@@ -82,10 +86,6 @@ The following steps should help troubleshoot any problems related to the **Autom
8286
> [!NOTE]
8387
> There is a known issue that prevents scripts stored in SharePoint from always appearing in the recently used list. This occurs when your admin turns off Exchange Web Services (EWS). Your SharePoint-based scripts are still accessible and usable through the file dialog.
8488
85-
## Platform limits
86-
87-
For a detailed list of limitations on the Office Scripts platform due to Excel, Power Automate, or other tools, see [Platform limits and requirements with Office Scripts](./platform-limits.md).
88-
8989
## Help resources
9090

9191
[Stack Overflow](https://stackoverflow.com/questions/tagged/office-scripts) is a community of developers willing to help with coding problems. Often, you'll be able to find the solution to your problem through a quick Stack Overflow search. If not, ask your question and tag it with the "office-scripts" tag. Be sure to mention you're creating an Office *Script*, not an Office *Add-in*.

docs/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ items:
9090
href: resources/samples/report-day-to-day-changes.md
9191
- name: Row and column visibility
9292
href: resources/samples/row-and-column-visibility.md
93+
- name: Set conditional formatting for cross-column comparisons
94+
href: resources/samples/conditional-formatting-parameters.md
9395
- name: Beyond the basics
9496
items:
9597
- name: Combine worksheets into a single workbook

0 commit comments

Comments
 (0)