Office Scripts samples and scenarios

This section contains Office Scripts based solutions that help end users achieve automation of daily tasks. It contains realistic scenarios that users face and provides detailed solutions.

  • Basics showcase common examples that make up larger scripts. Most don't need a specific workbook or dataset and can be run in the workbook of your choice.
  • Beyond the basics are samples that are more involved or solve a particular problem. Some use Power Automate with an Office Script as a integral part of the flow.
  • Scenarios are a few larger samples that demonstrate real-world use cases.
  • Contributions from the community are samples from members of the Office Scripts community, often light-hearted in nature.

Important

Be sure you meet the prerequisites for Office Scripts before trying the samples. The requirements for your Microsoft 365 subscription and account are found under the Office Scripts for Excel overview "Requirements" section.

Basics

Project Details
Range samples These samples show how to work the Range object, which is central to most scripts.
Table samples A collection of samples that show common interactions with Excel tables.
Add comments in Excel This sample adds comments to a cell including @mentioning a colleague.
Add images to a workbook This sample adds an image to a workbook and copies an image across sheets.
Copy multiple Excel tables into a single table This sample combines data from multiple Excel tables into a single table that includes all the rows.
Create a workbook table of contents This sample creates a table of contents with links to each worksheet.
JavaScript Date samples A collection of samples that show how to translate between JavaScript and Excel date formats.
Record day-to-day changes in Excel and report them with a Power Automate flow This sample uses a scheduled Power Automate flow to record daily readings and report the changes.
Row and column visibility samples A collection of samples that demonstrate how to show, hide, and freeze rows and columns.
Set conditional formatting for cross-column comparisons This sample applies formatting based on values in adjacent columns. It also gets user input through script parameters.

Beyond the basics

Check out the following end-to-end project that automates sample scenarios along with full scripts, sample Excel files used, and videos (hosted on YouTube).

Project Details
Combine worksheets into a single workbook This sample uses Office Scripts and Power Automate to pull data from other workbooks into a single workbook.
Convert CSV files to Excel workbooks This sample uses Office Scripts and Power Automate to create .xlsx files from .csv files.
Cross-reference workbooks This sample uses Office Scripts and Power Automate to cross-reference and validate information in different workbooks.
Count blank rows in a specific sheet or in all sheets 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.
Email chart and table images This sample uses Office Scripts and Power Automate actions to create a chart and send that chart as an image by email.
Manage calculation mode in Excel This sample shows how to use the calculation mode and calculate methods in Excel using Office Scripts.
Move rows across tables This sample shows how to move rows across tables by saving filters, then processing and reapplying the filters.
Output Excel data as JSON This solution shows how to output Excel table data as JSON to use in Power Automate.
Remove hyperlinks from each cell in an Excel worksheet This sample clears all of the hyperlinks from the current worksheet.
Run a script on all Excel files in a folder 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.
Use external fetch calls This sample uses fetch to get information from GitHub for the script.
Write a large dataset This sample shows how to send a large range as smaller subranges.

Scenarios

Office Scripts can automate parts of your daily routine. These day-to-day tasks often exist in unique ecosystems, with Excel workbooks that are set up in particular ways. These larger scenario samples demonstrate such real-world use-cases. They include both the Office Scripts and the workbooks, so you can see the scenario from end to end.

Scenario Details
Analyze web downloads This scenario features a script that parses web traffic records to determine a user's country of origin. It showcases the skills of text parsing, using subfunctions in scripts, applying conditional formatting, and working with tables.
Fetch and graph water-level data from NOAA This scenario uses an Office Script to pull data from an external source (the NOAA Tides and Currents database) and graph the resulting information. It highlights the skills of using fetch to get data and using charts.
Grade calculator This scenario features a script that validates an instructor's record for their class's grades. It showcases the skills of error checking, cell formatting, and regular expressions.
Schedule interviews in Teams This scenario shows how to use an Excel spreadsheet to manage interview meeting times and make a flow to schedules meetings in Teams.
Task reminders This scenario uses an Office Script in a Power Automate flow to send reminders to coworkers to update a project's status. It highlights the skills of Power Automate integration and data transfer to and from scripts.

Community contributions and fun samples

We welcome contributions from our Office Scripts community! Feel free to create a pull request for review.

Project Details
Game of Life The "Ready Player Zero" blog by Yutao Huang on the Excel Tech Community includes a script to model John Conway's The Game of Life.
Punch clock button This script was contributed by Brian Gonzalez. The scenario features a script and a script button that records the current time.
Seasons greetings animation This script was contributed by Leslie Black in the spirit of the holiday season! It's a fun script that shows a singing Christmas tree in Excel using Office Scripts.

Leave a comment

Feel free to leave a comment, make a suggestion, or log an issue by using the Feedback section at the bottom of the specific sample's documentation page.