-3

I have code that is pulling rows from google sheet into google slide. However, I want to add logic which first deletes all slides after the 2nd slide, if there are any. Then, it should do all the manipulation(replace text stuff) below. How do I do this?

function generateSlides() {
  var dataSpreadsheetUrl = "https://docs.google.com/spreadsheets/d/1kLb0bIVeDTb8He"; 
  var ss = SpreadsheetApp.openByUrl(dataSpreadsheetUrl);
  var deck = SlidesApp.getActivePresentation();
  var sheet = ss.getSheetByName('Form_Responses');
  var values = sheet.getRange('A2:G20').getValues();
  var slides = deck.getSlides();
  var templateSlide = slides[1];
  var presLength = slides.length;
  
  values.forEach(function(page){ 
  if(page[0]){
    
   var Email = page[1]; #column 2
   var Name = page[2]; #column 3
   var timestamp = page [0]; # column 1. 


   var shapes = (newSlide.getShapes());
     shapes.forEach(function(shape){
       shape.getText().replaceAllText('{{Email}}',Email);
       shape.getText().replaceAllText('{{Name}}',Name);
       
    }); 
   presLength = slides.length; 
   newSlide.move(presLength); 
  } // end our conditional statement
  }); //close our loop of values
  
}
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
cesarteaser
  • 111
  • 1
  • 8
  • 1
    The Q title should summarize the body of question but they are completely different. What do you want to ask? – Rubén Aug 20 '20 at 05:24
  • You apear to be missing the section of your code that **first deletes all slides after the 2nd slide, if there are any** Please include a [MRE](https://stackoverflow.com/help/minimal-reproducible-example) and describe any issues with it. – Linda Lawton - DaImTo Aug 20 '20 at 08:06

1 Answers1

1
  • Use getSlides to obtain an array of all slides of the presentation
  • Access the individual slides by their index which corresponds to their position in the presentation
  • Create a for loop to itereate through all slides of interest based on their index
  • Use Slide.remove() to remove slides

Sample snippet

  var slides = deck.getSlides();
 //change i to any other index if desired
  for (var i = 2; i < slides.length; i++){
    slides[i].remove()
  }
ziganotschka
  • 25,866
  • 2
  • 16
  • 33