Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

315
Visualizações
How to insert images according to creation date with google apps script?

I'm looking to inesrt image files into google slides according to the date they were created. I have the following code, which sequentually inserts images to googles slides from a drive folder:

function makeSlides() {
  
  var presentation = SlidesApp.openById(slideID);
  var folder = DriveApp.getFolderById(folderID);
  var contents = folder.getFiles()
  
  var file;
  var i = 1;
  
  while (contents.hasNext()) {
    
    var file = contents.next();
  
    data = file.getId(); 
    
    // insert above image
    
    var image = DriveApp.getFileById(data);
    var slide = presentation.getSlides()[i];
    var image = slide.insertImage(image);
    slide = presentation.appendSlide(SlidesApp.PredefinedLayout.BLANK);    
    i++;
 
  }

}

I would like to alter it so that the images are added by the date they were created (either newest or oldest). Any help received will be greatly appreciated. Thanks.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I believe your goal is as follows.

  • You want to retrieve the image files from the specific folder.
  • You want to put the retrieved images to Google Slides in order of the created date of the file.
  • You want to achieve this using Google Apps Script.

In this case, how about the following modification?

When the method of "Files: list" in Drive API is used, the file list can be retrieved in order of the created date. This is used for the modification.

Modified script:

Before you use this script, please enable Drive API at Advanced Google services.

function makeSlides() {
  var slideID = "###"; // Please set your Google Slides ID.
  var folderID = "###"; // Please set your folder ID.

  var presentation = SlidesApp.openById(slideID);
  var files = Drive.Files.list({orderBy: "createdDate asc", q: `'${folderID}' in parents and trashed=false and mimeType contains 'image'`, fields: "items(id)"}).items;
  files.forEach(({id}, i) => {
    var image = DriveApp.getFileById(id);
    var slide = presentation.getSlides()[i];
    var image = slide.insertImage(image);
    slide = presentation.appendSlide(SlidesApp.PredefinedLayout.BLANK);
  });
}
  • When this script is run, the file list is retrieved from the specific folder in order of the created date of the file. In this case, orderBy: "createdDate asc" is used. This mean that the 1st image is the oldest image. When you want to use the order that the 1st image is the newest image, please modify to orderBy: "createdDate desc".

References:

  • Files: list
  • forEach()
about 4 years ago · Juan Pablo Isaza Relatório

0

If you want them in specific order just sort them before adding.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda