I am trying to create a button in google sheets that run a script every time it is triggered. The script should first create a new copy of the template and then using that google sheet replace all placeholder text in that presentation with data from sheets. I am not sure why the code is not working as of now.
// The following creates the UI button in sheets (This works)
function onOpen() {
let ui = SpreadsheetApp.getUi();
ui.createMenu('Create Report')
.addItem('Create Report', 'executeAll')
.addToUi();
}
function executeAll (){
var reportTemplate = DriveApp.getFileById('Presentation ID goes Here');
var copiedTemplate = reportTemplate.makeCopy('New Report', DriveApp.getFolderById("Folder ID Goes here"));
var skeleton = SlidesApp.openById(copiedTemplate.getId());
var slides = skeleton.getSlides();
return slide1();
function slide1 (){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('App Script Input Sheet');
var data = sheet.getRange('E1:F26').getValues;
var slide1 = slides[0];
var newslide1 = slide1.duplicate();
var shapes = (newslide1.getShapes());
shapes.forEach(function(shape){
shape.getText().replaceAllText('{{Date}}',data[2]);
shape.getText().replaceAllText('{{Title}}',data[3]);
shape.getText().replaceAllText('{{Value 1}}',data[4]);
shape.getText().replaceAllText('{{Value 2}}',data[5]);
//there are more to be replaced. will add once code works.
});
}
}