Search code examples
google-apps-scriptgoogle-sheetscopy-pastegoogle-slides

Is there a way to take text from a specific slide on Google Slides and add it to a row on a Google Sheet spreadsheet?


I'm looking for a way to take text from a specific slide on Google Slides and add it to a row on a Google Sheet spreadsheet.

I've done an extensive search but have only found instances where people want to generate slides based on sheets data or insert charts from sheets into slides. There don't seem to be any instances where people want to connect the apps the other way round.

What I would like to do is:

  1. Find the document tile, a url to the document and the text on page 4 of all the slides documents in a specific folder and its subfolders on Google Drive.
  2. Copy the title of the document, a link to the document and the text on page 4 and add them to a new row on the google sheet spreadsheet.

Would this be possible at all?

I have not really been able to try anything as I cannot find any examples of linking Google Slides to Google Sheets in this way and I would like to know if it is theoretically possible, in which case I can keep trying or if it's impossible and therefore I should give up trying.


Solution

  • Something like this:

    // this script is bound to the Slides Presentation
    // select the text to be copied to the Sheet
    // then run the script.
    function copySelection2Sheet(){
    
      var pres = SlidesApp.getActivePresentation()
    
      // get the selected text
      var selection = pres.getSelection()
      var textRange = selection.getTextRange().asString();
      // Logger.log('DEBUG: Text selected: ' + textRange);
    
      // open the Sheet and paste the data
      var sheetID = "1R0YRo7tywS27T0RUf3bq4vz425kx_Uu6T8GVR4lQG0M"
      var ss = SpreadsheetApp.openById(sheetID)
      var sheet = ss.getSheetByName("Sheet1")
      var range = sheet.getRange("A1")
      range.setValue(textRange)
    
    }
    

    SAMPLE - Slide

    slide

    SAMPLE - Sheet

    sheet