Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Duplicate master Google Slides deck + Populate it from Sheets

I have two scripts that work well separately but I need to combine them.

What I am trying to achieve is that from a Google Sheets, someone will run a script and:

  1. A copy of a master Google Slides deck will be made and the name will be updated based on a sheet called ‘Generate’
  2. This copy will be updated with values from the sheet called ‘Data’, using placeholders

For point 1 I have this code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

function createFolderAndFiles() {
  const templateGetStarted = '<ID OF MY TEMPLATE DECK>';

let sheet = SpreadsheetApp.getActive().getSheetByName('Generate');
let data = sheet.getDataRange().getValues();

let wbrDate = data[1][0];
let getStarted = data[1][1];


  DriveApp.getFileById(templateGetStarted).makeCopy(`WBR - ${wbrDate}`)
}

And for point 2 I have this code:

function fillTemplate() {

 var PRESENTATION_ID = "<THE ID OF THE JUST CREATED COPY OF THE TEMPLATE DECK IN POINT 1>";

 var presentation = SlidesApp.openById(PRESENTATION_ID);

 var values = SpreadsheetApp.getActive().getSheetByName('Data').getDataRange().getValues();

 values.forEach(function(row) {
   var templateVariable = row[0]; // First column contains variable names
   var templateValue = row[1]; // Second column contains values
   presentation.replaceAllText(templateVariable, templateValue);
 });

}

So as I mentioned, they work great separetely. I just need to find a way to combine them both into 1 function that you can run and a copy of the template deck will be made and it will be filled automatically with data from the spreadsheet.

Any help is much appreciated!

>Solution :

You can try meeting your last line of the first function and first line of the second one

var PRESENTATION_ID = DriveApp.getFileById(templateGetStarted).makeCopy(`WBR - ${wbrDate}`).getId()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading