function fillTemplate() {
var Presentation = SlidesApp.openById("id");
var sh = SpreadsheetApp.openById("id").getSheetByName("Sheet1");
var values = sh.getDataRange().getValues();
values.forEach(function(column){
var templateVariable= column[0];
var templateValue= column[1];
Presentation.replaceAllText(templateVariable,templateValue)
});
}
The code is supposed to replace variables inside a slide with information inside a google sheet. it shows no errors, however there is no change in the slide itself. is there something i got wrong?
i tried refreshing the google slide and trying more elaborate ways of changing the text including tables but all doesn't work. I was expecting the text that i entered in the google sheet to automatically fill in the slide variables.
(google sheet and slide template underneath) (don't ask about the text) slide template google sheet values
values
is a 2-dimensional array like [[col1, col2,,,]]
. So, column
of values.forEach(function(column){
is a row value. And also, in this case, the header row is used in the 1st loop.When these points are reflected in your script, it becomes as follows.
function fillTemplate() {
var Presentation = SlidesApp.openById("id");
var sh = SpreadsheetApp.openById("id").getSheetByName("Sheet1");
var [header, ...values] = sh.getDataRange().getDisplayValues();
values.forEach(row =>
row.forEach((col, j) => Presentation.replaceAllText(header[j], col))
);
}