Share via

Office Script - Run an excel script from Power Automate

Anonymous
2023-01-24T16:58:01+00:00

Hello,

I'm new on Office Script and I'm trying to run a rather simple Office Script on excel from power automate to fill specific cells on the excel file.

The script take three variables from Power automate and should fill specific cells based on these.

Some parts of this code worked sometimes and sometimes not which is confusing me more than anything else.

function main( workbook: ExcelScript.Workbook,CMQ_Name: string,Version: string, PT_Name: string ) 

{ // create reference for each sheet in the excel documentlet NAMES = workbook.getWorksheet("CMQ_NAMES");let TERMS = workbook.getWorksheet("CMQ_TERMS");

//------Part 1: Update entries in sheet CMQ_NAMESNAMES.getRange("A2").setValues(CMQ_Name);NAMES.getRange("D2").setValues(Version);

//Update entries in sheet CMQ_TERMSTERMS.getRange("A2").setValues(CMQ_Name);

//-------Part 2: work with PT_Name//Split PT_Namelet ARRAY1: string[] = PT_Name.split(";"); let CELL: string;

let A: string = "A"

NAMES.getRange("E4").setValues(ARRAY1[0]); //TEST: show initial value [0]

ARRAY1.pop; // remove value [0]

NAMES.getRange("E4").setValues(ARRAY1[0]); //TEST show new value [0]

for (var i = 0; i < ARRAY1.length; i++) {CELL = A.concat(i.toString());NAMES.getRange(CELL).setValues(ARRAY1[i]);}}

I have several problems:

  1. The part in red are detected as a problem and I have no idea why: Argument of type 'string' is not assignable to parameter of type '(string | number | boolean)[ ][ ]'.

Search returned that there was a need to "Restarting VSCode" to fix it, but it didn't seems to work and I'm not sure if this is the problem?

  1. I couldn't find a way to use a variable as address to select a specific cell to write in, which is preventing the for loop at the end from working from working.

The idea of the for loop is to get a string with names separated by ";", split it into a vector, then enter each of the names in the column B, one under each other starting at B2.

I've been bashing my head against this for a week now without solving it.

Could you kindly take a look?

Thanks!

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

  1. Anonymous
    2023-01-25T06:59:22+00:00

    Hi WarlowL,

    Greetings! Thank you for posting to Microsoft Community.

    You can get help for Power Automate Script from Microsoft Power Automate Community.

    Forums - Power Platform Community (microsoft.com)

    Best Regards,

    Snow Lu

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful