Home > Software design >  Auto fill google slide template from google spreadsheet data
Auto fill google slide template from google spreadsheet data

Time:07-03

Am new to google app script.

Am trying to Auto fill a google slide template with some data from spread sheet.

I created a list in the spreadsheet containing the data.

function onOpen() { const ui = SpreadsheetApp.getUi();
ui.createMenu('COS Auto Fill') .addItem('COS Auto Fill', 'Presentation_Call') .addToUi(); }

function Presentation_Call() { var range = SpreadsheetApp.getActiveSheet().getRange('G1'); var value = range.getValue();}

function fillTemplate() {var presentation = SlidesApp.openById(Presentation_Call);

var values = SpreadsheetApp.getActive().getDataRange().getValues();

values.forEach(function(row) { var templateVariable = row[1];
var templateValue = row[2]; presentation.replaceAllText(templateVariable, templateValue); });}

Spreadsheet Link

https://docs.google.com/spreadsheets/d/1J11tI2O5NUEr_2HpYYgCrseh9U_0KWF5YJeZ2uOV2gE/edit#gid=0

Google Slides Link

https://docs.google.com/presentation/d/10vGaLWo1ro1d3jzUrEVwOjozHHkxWCMzHEcikqwl_08/edit#slide=id.p1`

What I want to do is replacing the {{Number}} in the google slides template with the corresponding data from Gsheet.

By opening the presentation using the presentation ID that is being called from a fixed cell in Gsheet then update the template variable.

Thanks in advance.

CodePudding user response:

There are a couple of issues with your project:

  1. The ID in G1 is enclosed in double quotes. Enter just the plain ID.
  2. In SlidesApp.openById(Presentation_Call), you pass in the function, rather than the return value of the function. Change it to SlidesApp.openById(Presentation_Call())
  3. The function Presentation_Call doesn't return anything. Add a return value; at the end.
  4. You add the function Presentation_Call to the menu. But I think you want to call fillTemplate instead. So, change that line to .addItem('COS Auto Fill', 'fillTemplate')

I made the changes here: https://docs.google.com/spreadsheets/d/1GzBgot6Q818rV488Bfx_Q8yknUCvjHUzyInfWob9XzU

  • Related