I am working on a slide that would take dynamic data from Google sheet.
- I want to keep the slide template
- Update the slide values in real-time
I want to use Google app scripts to connect the data from the sheet to the slide. I am new to Java Scripts and following a tutorial online to achieve this but with no luck.
My 2 files are set up as follows
and the slides I am working on can be found here
A copy of the data can also be found here
The tutorial I am following is found in this link
Below is the code I have implemented but the problem is it does not work and tries to create multiple pages and repeat same value on each page. I only want one page with the values updated from the sheet Your help would be grately appareciated. Thank you
function generateLandingPagesReport() {
var dataSpreadsheetUrl = "https://docs.google.com/spreadsheets/d/1UccsFtqKKsXhlus4-02dXfJP0ECcCsBUmLNZajJnS_4/edit"; //make sure this includes the '/edit at the end
var ss = SpreadsheetApp.openByUrl(dataSpreadsheetUrl);
var deck = SlidesApp.getActivePresentation();
var sheet = ss.getSheetByName('metrics'); // sheet name
var values = sheet.getRange('C4:L12').getValues(); // range for values
var slides = deck.getSlides();
var templateSlide = slides[0];
var presLength = slides.length;
values.forEach(function(page){
if(page[0]){
var Current = page[2];
var Target = page[3];
var Emea = page[5];
var Depac = page[7];
var Emma = page[9];
var Comment = page[11];
templateSlide.duplicate(); //duplicate the template page
slides = deck.getSlides(); //update the slides array for indexes and length
newSlide = slides[2]; // declare the new page to update
var shapes = (newSlide.getShapes());
shapes.forEach(function(shape){
shape.getText().replaceAllText('{{Current}}',Current);
shape.getText().replaceAllText('{{Target}}',Target);
shape.getText().replaceAllText('{{Emea}}',Emea);
shape.getText().replaceAllText('{{Depac}}',Depac)
shape.getText().replaceAllText('{{Emma}}',Emma);
shape.getText().replaceAllText('{{Comment}}',Comment);
});
presLength = slides.length;
newSlide.move(presLength);
} // end our conditional statement
}); //close our loop of values
//Remove the template slide
templateSlide.remove();
}
duplicate()
is used in the loop. By this, new slide is inserted every loop. I think that this is one of several reasons of your issue. And, unfortunately, I couldn't see the sample ofand the slides I am working on can be found here
. I cannot understand about your actual situation from the image. So in order to correctly understand about your situation, can you explain about the detail of your Google Slides? – Tanaike