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:
- 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?
- 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!