0

I'm creating a new Google Slide file based on template, once created I need to stop the embedded charts from updating if the source sheet changes (this is for monthly reports where the underlying will change regularly).

I'm using the Google Slides API for Google Apps Script library (thanks to Wesley Chun and Martin Hawksey) and can have got search and replace working for text.

I'm not however seeing anything in the library that would permit a change the chart properties. I can create a new chart or force a refresh.

Any help appreciated.

Kos
  • 4,890
  • 9
  • 38
  • 42
ajcooper
  • 239
  • 3
  • 15
  • Have you checked this [documentation](https://developers.google.com/chart/interactive/docs/customizing_charts) about customizing Google Charts? You can use Google Chart Tools with their default setting - all customization is optional and the basic setup is launch-ready. However, charts can be easily customizable in case your webpage adopts a style which is at odds with provided defaults. You can also check on this [related SO thread](http://stackoverflow.com/questions/28753125/) to customize a Google chart using Apps Script. – abielita Feb 01 '17 at 02:44

2 Answers2

1

There isn't API support for unlinking an existing chart to prevent users from refreshing it. Your best bet is likely to delete the chart and recreate it in your final presentation. You should be able to get the chart ID, spreadsheet ID and page element transform off of a presentation.get() or presentation.pages.get() and use that to reinsert the chart to preserve the position and content.

Maurice Codik
  • 598
  • 2
  • 6
0

I've gone with the following which deletes and recreates all charts in the slides file;

for (var j in SLIDES.presentationsGet(DECK_ID).slides) {
  var slide = SLIDES.presentationsGet(DECK_ID).slides[j];
  for (var i in slide['pageElements']){
    var obj = slide['pageElements'][i];
    if (obj['sheetsChart']) {

      // delete it and recreate as static image
      var reqs = [
        {'deleteObject': {'objectId': obj['objectId']}},
        {'createSheetsChart': {
          'spreadsheetId' : obj["sheetsChart"]["spreadsheetId"],
          'chartId' : obj["sheetsChart"]["chartId"],
          'elementProperties' : {
            'pageObjectId': slide['objectId'],
            'size' : obj["size"],
            'transform' : obj["transform"],
          }
        }
      }
    ];
    SLIDES.presentationsBatchUpdate(DECK_ID, {'requests': reqs})
  }
}
ajcooper
  • 239
  • 3
  • 15