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:
- The ID in G1 is enclosed in double quotes. Enter just the plain ID.
- In
SlidesApp.openById(Presentation_Call)
, you pass in the function, rather than the return value of the function. Change it toSlidesApp.openById(Presentation_Call())
- The function
Presentation_Call
doesn't return anything. Add areturn value;
at the end. - You add the function
Presentation_Call
to the menu. But I think you want to callfillTemplate
instead. So, change that line to.addItem('COS Auto Fill', 'fillTemplate')
I made the changes here: https://docs.google.com/spreadsheets/d/1GzBgot6Q818rV488Bfx_Q8yknUCvjHUzyInfWob9XzU