TransWikia.com

Consolidating Google Slides

Web Applications Asked by user251141 on January 5, 2022

I am constructing a small app to consolidate slide decks within Google Drive.

For the most part the app works great. However, when I append a slide deck it only adds the first slide.

currentPresentation.appendSlide(org1Slides.getSlides()[0]);

Obviously it only returns the first slide because of [0]. I have tried removing the [0] and .getSlides() [0] portions altogether, which results in an error. I cannot find a way in the documentation to list more than one slide. I have also tried using a variation of for loops to pull each slide, but my current code just gets ignored.

for (var i = 0; i < org1Slides.length; i++) {
  currentPresentation.appendSlide(org1Slides.getSlides()[i]);
}

and

for (slide in org1Slides) {
      currentPresentation.appendSlide(org1Slides.getSlides()[slide]);
    }

I am sure I am missing something small, but can someone point me in the direction of appending each slide from a presentation.

The desired outcome is that the code appends the entire slide deck to the overall presentation. The number of slides in each presentation is variable, so I can’t simply list each slide to be appended separately.

Full Code:

function consolidateSlides() {
  // use the 'Org Base' slides as the baseline
  var presentationId = '{presentation id hidden}';
  
  // set current month, rename to current slide deck
  var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];;
  var date = new Date();
  var currentMonth = months[date.getMonth()] + ' ' + date.getFullYear();
  var copyTitle = 'Meeting ' + currentMonth;
  var copyFile = {
    title: copyTitle,
  };
  copyFile = Drive.Files.copy(copyFile, presentationId);

  // prepare current slide deck for appending org slides
  var currentPresentation = SlidesApp.openById(copyFile.id);
  
  // append org1 slides
  var org1Slides = SlidesApp.openById('{presentation id hidden}');
  currentPresentation.appendSlide(org1Slides.getSlides()[0]);
    
  // append org2 slides
  var org2Slides = SlidesApp.openById('{presentation id hidden});
  currentPresentation.appendSlide(org2Slides.getSlides()[0]);
  
  // append org3 slides
  var org3Slides = SlidesApp.openById('{presentation id hidden}');
  currentPresentation.appendSlide(org3Slides.getSlides()[0]);
  
  // append org4 slides
  var org4Slides = SlidesApp.openById('{presentation id hidden}');
  currentPresentation.appendSlide(org4Slides.getSlides()[0]);

  // append org5 slides
  var org5Slides = SlidesApp.openById('1{presentation id hidden}');
  currentPresentation.appendSlide(org5Slides.getSlides()[0]);

  // append org6 slides
  var org6Slides = SlidesApp.openById('{presentation id hidden}');
  currentPresentation.appendSlide(org6Slides.getSlides()[0]);

};

One Answer

I solved it after a few more hours of digging through documentation.

The openById() function does not return a list of slides. Using getSlides() provides a list of slides through which the for loop can iterate.

So

  // append org1 slides
  var org1Slides = SlidesApp.openById('{presentation id hidden}');
  currentPresentation.appendSlide(org1Slides.getSlides()[0]);

Turned in to:

  // append org1 slides
  var org1Slides = SlidesApp.openById('{presentation id hidden}');
  var currentSlides = org1Slides.getSlides();
  for (slide in currentSlides) {
    currentPresentation.appendSlide(org1Slides.getSlides()[slide]);
  }

Answered by user251141 on January 5, 2022

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP