How to automatically update charts linked to Google Sheets?

AviG picture AviG · Jun 12, 2017 · Viewed 21.2k times · Source

I have a Google Slides presentation with charts that are linked to a specific Google Sheets Spreadsheet.

As there are many charts in the presentation, I'm looking for a way to update all these linked charts automatically, or at least all of them at once.

What is the best way to do this?

Answer

Aleister Tanek Javas Mraz picture Aleister Tanek Javas Mraz · Jan 14, 2018

You can add a custom function to a dropdown menu in the Slides UI with the following script. This gets the slides from the current presentation, loops through them, gets any charts in each slides and refreshes (updates) them.

function onOpen() {
  var ui = SlidesApp.getUi();
  ui.createMenu('Custom Menu')
  .addItem('Batch Update Charts', 'batchUpdate')
  .addToUi();
}

function batchUpdate(){

  var gotSlides = SlidesApp.getActivePresentation().getSlides();

  for (var i = 0; i < gotSlides.length; i++) {
    var slide = gotSlides[i];
    var sheetsCharts = slide.getSheetsCharts();
    for (var k = 0; k < sheetsCharts.length; k++) {
      var shChart = sheetsCharts[k];
      shChart.refresh();
    }
  }
}

Note: The functionality to update/refresh linked Slides doesn't appear to exist at the time of this response.