web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Office Script And Powe...
Power Automate
Unanswered

Office Script And Power Automate to export Images from Sharepoint Document Library to Excel

(0) ShareShare
ReportReport
Posted on by 67

Hi everyone,

 

I am generating a BoQ Report in excel for every MSME I have in a Sharepoint List using Power Automate & Office Script. Everything was going well as I followed @DamoBird365's tutorial (link: https://www.youtube.com/watch?v=K3WtUTWZ-DQ&ab_channel=StuartRidout%3AProductivityCoach)

 

My problem is that in my excel report there is an extra cell in every BoQ row that should have the image of that BoQ which is stored in a Sharepoint Document Library.

 

How can I insert into every row's cell the related image? Kindly check my flow and script below:

 

My FlowMy Flow

 

Closer look BoQ Items Array field mappingCloser look BoQ Items Array field mapping

 

As for my Office Script, it is working fine except for the image, for which I want to know how can I set the image along with the array to form a row.

 

 

async function main(workbook: ExcelScript.Workbook, msme: MSME[], boqs: BoQs[],) 
{
 // Get the first worksheet
 const sheet = workbook.getFirstWorksheet();

 //Update MSME Details
 sheet.getRange("D5").setValue(msme[0].businessName);
 sheet.getRange("D6").setValue(msme[0].representative);
 sheet.getRange("D7").setValue(msme[0].phoneNumber);
 sheet.getRange("D8").setValue(msme[0].suburb);
 sheet.getRange("H5").setValue(msme[0].numberOfEmployees);
 sheet.getRange("H6").setValue(msme[0].longitude);
 sheet.getRange("H7").setValue(msme[0].latitude);

 //Update BoQ Lines
 const boqOffset = 11; //starting row for BoQ items list
 for (let i = 0; i < boqs.length; i++) {
 const currentBoQs = boqs[i];

 // Fetch the image from a URL.
 const link = currentBoQs.imageLink;
 const response = await fetch(link);
 // Store the response as an ArrayBuffer, since it is a raw image file.
 const data = await response.arrayBuffer();
 // Convert the image data into a base64-encoded string.
 const image = convertToBase64(data);

 // Add the image to a worksheet.
 workbook.getWorksheet("Sheet1").addImage(image) //Want to set this line into array below instead of currentBoQs.imageLink
 
 //Set BoQ item row into array then fill into excel row
 const formattedBoqs = [[currentBoQs.boqNumber, currentBoQs.location, currentBoQs.category, currentBoQs.item, currentBoQs.damageLevel, currentBoQs.repairType, currentBoQs.unit, currentBoQs.quantity, currentBoQs.width, currentBoQs.BoQlength, currentBoQs.thickness, currentBoQs.direction, currentBoQs.imageLink , currentBoQs.note]];
 const boqCell = `A${boqOffset + i}:N${boqOffset + i}`;
 sheet.getRange(boqCell).setValues(formattedBoqs);
 }
}

interface BoQs {
 boqNumber: number,
 location: string,
 category: string,
 item: string,
 damageLevel: string,
 repairType: string,
 unit: string,
 quantity: string,
 width: string,
 BoQlength: string,
 thickness: string,
 direction: string,
 imageLink: string,
 note: string,
}

interface MSME {
 businessName: string,
 representative: string,
 phoneNumber: string,
 suburb: string,
 numberOfEmployees: number,
 longitude: number,
 latitude: number,
 note: string,
}

 

 

 

 

 

Categories:
I have the same question (0)
  • Yutao Huang Profile Picture
    Microsoft Employee on at

    I think you can use setValues() to set the content of all the non-image cells. But you will need to handle the image cell separately.

     

    Below is one possible way to handle the image cell, assuming anchorCell is the range of the cell where you want to place the image into that row.

     

    const image = workbook.getWorksheet("Sheet1").addImage(imageBase64);
    image.setTop(anchorCell.getTop());
    image.setLeft(anchorCell.getLeft());
    image.setHeight(anchorCell.getHeight());
    image.setWidth(anchorCell.getWidth());
    image.setPlacement(ExcelScript.Placement.twoCell);

     

    The trick is to properly set the image position/dimension (left/top/width/height) to align with the cell itself and make sure to use the twoCell placement so the image can resize and move with the cell.

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard