I'm trying to write a gsheet appscript that replaces an image in google slide. Ultimately, i want to iterate through the spreadsheet and for each row create a new slide with the image of the row in the spreadsheet. Currently, I can't get it to work once.
My code is below:
function updatePresentation() {
// Replace with your actual presentation ID
const PRESENTATION_ID = "My_ID"
// Get the spreadsheet object
const sheet = SpreadsheetApp.getActiveSheet();
// Get data range (excluding header row)
const dataRange = sheet.getDataRange().getValues().slice(1);
// Access the Slides service
const slidesApp = SlidesApp.openById(PRESENTATION_ID);
// Get the template slide
const templateSlide = slidesApp.getSlides()[0];
const pageElements = templateSlide.getPageElements();
Logger.log(pageElements)
imageName = "test01.png"
const imageBlob = DriveApp.getFilesByName(imageName).next().getBlob();
const left = 0; // The x-coordinate of the top left corner of the image
const top = 0; // The y-coordinate of the top left corner of the image
const width = 200; // Width of the image
const height = 100; // Height of the image
// Add the image to the slide
Logger.log(templateSlide.insertImage(imageBlob, left, top, width, height));
}
The current error message is " Exception: The image you are trying to use is invalid or corrupt."
I've tried this a number of different ways with no success. Any help would be appreciated.