Search code examples
google-apps-scriptgoogle-sheetsgoogle-sheets-apigoogle-slides-apigoogle-slides

automatically refresh Sheets chart in Google Slides


I have a chart within google sheets that I would like to have automatically update in google slides every hour. I know you can refresh using the Tools menu and selecting linked objects but I would really like to automate this process without use of a Slides AddOn


Solution

    • You want to refresh a chart in Google Slides every 1 hour.
    • The chart was put from Google Spreadsheet.
    • You want to achieve this using Google Apps Script.

    If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.

    Pattern 1:

    In this pattern, all charts in all slides in the Google Slides are refreshed.

    Sample script:

    function myFunction() {
      var slidesId = "###";  // Please set the Slides ID.
    
      SlidesApp.openById(slidesId).getSlides()
      .forEach(function(s) {
        s.getSheetsCharts().forEach(function(c) {
          c.refresh();
        });
      });
    }
    

    Pattern 2:

    In this pattern, all charts in 1st slide in the Google Slides are refreshed.

    Sample script:

    function myFunction() {
      var slidesId = "###";  // Please set the Slides ID.
    
      SlidesApp.openById(slidesId).getSlides()[0]
      .getSheetsCharts()
      .forEach(function(c) {
        c.refresh();
      });
    }
    

    Note:

    References:

    If I misunderstood your question and this was not the direction you want, I apologize.