Passing Data from Power Automate to Excel sheet

Office Scripts are written in TypeScript, which is a powerful programming language based on JavaScript and used in many other applications out of Excel. One of the major concepts in TypeScript/JavaScript (as well as in other programming languages) is the functions, which represent a block of reusable code that performs some specific tasks. While this article doesn’t investigate deeply how functions operate, it is important to understand that functions can have parameters, which are values sourced from external inputs and employed within the function’s internal logic.

As per my previous articles, we know how to set the values in any cell of the workbook and how to fill color in any cell.

Workbook

We have set static values in the active cell. In this article, we will see how to set the dynamic values from Power Automate

First, we need to add a new parameter to the function main, as this is how we can pass values from Power Automate to Office Scripts.

In the line 1, right after the workbook: ExcelScripts.Workbook, we add the parameter text, which has the data type string, as underlined in red (make sure to separate the parameters by comma). After that, in line 4, we just replace the default value “Hello office Script” for a reference to the text (without quotes), as underlined in green, which will now capture dynamically the value sent by Power Automate.

Let's add one more parameter to the function in the script and that parameter value we will take from Power Automate.

 Power Automate

Now, When we add the sheet into Power Automate, it will ask for parameter value. Whatever dynamic value we pass will be added to the worksheet.

Parameter value

And, at last, we need to run the flow.

After a successful run, the dynamic text we passed from Power Automate will be added to the active workbook.

Dynamic text

Home


Similar Articles