Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Syndicate_Admin
Administrator
Administrator

Office Script (TypeScript) code to advance one cell every time the code runs from Power Automate Excel Run Script

Hello, Coding Geniuses

I am pulling images from power automate into excel using the following Run script code:

 

function main(workbook: ExcelScript.Workbook, sheetName: string, address: string,     base64ImageString: string) {
  let sheet = workbook.getWorksheet(sheetName);
  let range = sheet.getRange(address);
  let OldDevSNimg = sheet.addImage(base64ImageString);

  for (let i = 0; i < 3; i++) {

    let nextcell = range.getOffsetRange(+1, 0);

    OldDevSNimg.setTop(nextcell.getTop());
    OldDevSNimg.setLeft(nextcell.getLeft());
    OldDevSNimg.setWidth(300);
    OldDevSNimg.setHeight(400);
    OldDevSNimg.setLockAspectRatio(true);
    OldDevSNimg.setPlacement;
    OldDevSNimg.incrementTop(3);
    OldDevSNimg.incrementLeft(5);

  }
}

 

The Power Automate flow is sending a column with multiple images from a SharePoint list which need to be put on their respective rows... The issue I'm having is each image comes across and is placed on top of one another.

I am struggling with a for loop or some way to dynamically change to the next row (in the same column) for each image coming across from power automate.

Or, is there a way to put a function in the 'Address' area of the Run Script action which will automatically move to the next excel row for every item in the 'Apply to each' action?

Flow Run Script.PNG

Any help would be greatly appreciated! Apologies as I am new to Type Script / Power Automate and just can't get the right syntax or expression.

 

Thanks in advance!

1 ACCEPTED SOLUTION
v-angzheng-msft
Community Support
Community Support

Hi, @Syndicate_Admin 

 

It seems that your question has been solved in other forums and I am quoting the solution here to help the community.
Here is the original answer:

This small example will start from cell A3 and keep offsetting down to the next row for 5 loops ...

function main(workbook: ExcelScript.Workbook)
{
  let worksheet = workbook.getActiveWorksheet();

  for(var i = 1; i <= 5; i++) {   
    var nextCell = worksheet.getCell(2, 0).getOffsetRange(i, 0);
    nextCell.setFormula("=ROW()");
  }
}

... getOffsetRange is moving from A3 by the amount of rows during each loop.

So this line of yours ...

let nextcell = range.getOffsetRange(+1, 0);

... really needs to factor in the iteration from your for loop (i.e. the value of i).

It should be more like this ...

let nextcell = range.getOffsetRange(i, 0);

... and your for loop should start from 1, not 0 ...

for (let i = 1; i <= 3; i++)

... something like that.

 

 

refer:

Office Script (TypeScript) code to advance one cell every time the code runs

 

 

Best Regards,
Community Support Team _ Zeon Zheng


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-angzheng-msft
Community Support
Community Support

Hi, @Syndicate_Admin 

 

It seems that your question has been solved in other forums and I am quoting the solution here to help the community.
Here is the original answer:

This small example will start from cell A3 and keep offsetting down to the next row for 5 loops ...

function main(workbook: ExcelScript.Workbook)
{
  let worksheet = workbook.getActiveWorksheet();

  for(var i = 1; i <= 5; i++) {   
    var nextCell = worksheet.getCell(2, 0).getOffsetRange(i, 0);
    nextCell.setFormula("=ROW()");
  }
}

... getOffsetRange is moving from A3 by the amount of rows during each loop.

So this line of yours ...

let nextcell = range.getOffsetRange(+1, 0);

... really needs to factor in the iteration from your for loop (i.e. the value of i).

It should be more like this ...

let nextcell = range.getOffsetRange(i, 0);

... and your for loop should start from 1, not 0 ...

for (let i = 1; i <= 3; i++)

... something like that.

 

 

refer:

Office Script (TypeScript) code to advance one cell every time the code runs

 

 

Best Regards,
Community Support Team _ Zeon Zheng


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.