cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Problematic
Frequent Visitor

import an image to excel by script through power automate

Hi All

I am trying to use the script to get an image from the SharePoint to the excel.  However I only get a bunch of characters like this after running the flow 

Problematic_3-1651646323083.png

the intended design should be like this

Problematic_4-1651646439186.png

I  can get the file content of the image by using base64 function  

Problematic_1-1651645936412.png

Problematic_2-1651645978135.png

In the excel script, what I wrote : 

Interface Answer {

chop : string;

 *(This is one of the steps to get the image file from the SharePoint list after the user input the required data to pull out)

let picture = selectedSheet.addImage(answer.chop);

picture.setTop(950);

picture.setLeft(440):

 

Can anyone  advise why I only get a bunch of characters instead of an image.  How to make the correct statement to import the image

 

Thanks in advance.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Yutao
Microsoft
Microsoft

You can give the image a name (with the setName API) after adding it to the worksheet:

 

function main(workbook: ExcelScript.Workbook, imageBase64: string)
{
  let picture = workbook.getWorksheet("Sheet5").addImage(imageBase64);
  picture.setName("image-name");
  picture.setTop(30);
  picture.setLeft(30);
}

 

 

And later in the script to delete the image:

 

function main(workbook: ExcelScript.Workbook) {
  let picture = workbook.getWorksheet("Sheet5").getShape("image-name");
  picture.delete();
}

 

 

Please note that image is a special type of shape in Excel, so you'll need to use getShape() to find it.

View solution in original post

4 REPLIES 4
Yutao
Microsoft
Microsoft

This flow and script worked for me:

Yutao_0-1652466134622.png

 

function main(workbook: ExcelScript.Workbook, imageBase64: string)
{
  let picture = workbook.getWorksheet("Sheet5").addImage(imageBase64);
  picture.setTop(30);
  picture.setLeft(30);
}

 

And the result:

Yutao_1-1652466201072.png

 

Do you mind sharing a bit more of your flow?

 

Problematic
Frequent Visitor

Thanks a lot.  It works.

 

However, I have another issue.   After adding the image to the excel and send this excel worksheet out by email, how can I remove the image from the excel as this excel is served as the master template.  I wrote a new script for the image deletion as follows :

This is what I wrote :

Problematic_0-1652494383232.png

how can I define the variable as the image added from previous script would be different everytime

 

Problematic_1-1652494499765.png

 

 

Yutao
Microsoft
Microsoft

You can give the image a name (with the setName API) after adding it to the worksheet:

 

function main(workbook: ExcelScript.Workbook, imageBase64: string)
{
  let picture = workbook.getWorksheet("Sheet5").addImage(imageBase64);
  picture.setName("image-name");
  picture.setTop(30);
  picture.setLeft(30);
}

 

 

And later in the script to delete the image:

 

function main(workbook: ExcelScript.Workbook) {
  let picture = workbook.getWorksheet("Sheet5").getShape("image-name");
  picture.delete();
}

 

 

Please note that image is a special type of shape in Excel, so you'll need to use getShape() to find it.

HI Yutao

 

Appreciate your support and thanks a lot. 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Users online (1,592)