-1

There is possible send string or object as a parameter to office script online, Any idea how to send only data, eg. another excel table with data, maybe some array?

hint: there is a action in Power Automate, which return "File Content", which is some JSON

Firstly, I thought, parse all "File content" from "get file content" action

Konrad
  • 51
  • 5
  • basically, Scenario 1: I have excel with a table, so I can use action "list rows in the table" then I get all rows (each as JSON). Sudhi has fully answered this question. Scenario 2: I have excel file with data but no table inside. I can "get file content", however this file content is file encoded to base64. As I tested functions like atob seems to not correctly working. I am considering is even possible decode base64 to array with string & numbers – Konrad Feb 15 '21 at 11:06

2 Answers2

2

You can pass a valid JSON as input and receive it in the script.

function main(workbook: ExcelScript.Workbook, file: YourFileInterface) {
    console.log(file.someProperty);
}

interface YourFileInterface {
  // define it
}

-- if for some reason you need to pass the file as a string, --

You can use JSON.parse() to parse it back to JSON in the script.

This project might be helpful to watch: https://github.com/sumurthy/officescripts-projects/tree/main/Excel%20and%20Teams%20Invite Also, check out other projects that receive/uses JSON parameter as a string and parses in the script.

--

Could you also add more details around your scenario so that others can understand the question a little better? If you need further help, please add a comment.

Sudhi Ramamurthy
  • 2,358
  • 1
  • 10
  • 14
1

Just mark your parameter as an array type. It can be a string array if you want to keep it simple. If you want to go more advanced, you can make it an object array or even an object multi-dimensional array as long as the object type is defined by an interface.

Example:

interface Test {
  prop1: string;
  prop2: number;
}

function main(workbook: ExcelScript.Workbook, param: Test[][]) {
  console.log(param);
}

in Power Automate gives Run Script nested interface parameter

This allows you to send a parameter of type { prop1: string; prop2: number; } to an Office Script.

WeffJen
  • 70
  • 4