Apps Script example · 7 min read

Refresh a Sheets Chart Embedded in Google Slides: Copy-Paste Apps Script Pattern

Working refresh a sheets chart embedded in google slides example in Apps Script—copy-paste code, common mistakes, and when to get it built professionally.

SlidesSheetsCharts

Linked charts pasted from Sheets into Slides look convenient until the underlying data changes and the chart in the deck quietly falls out of date because nobody remembered to click Update.

This script takes a different approach: it grabs a chart object directly from a spreadsheet, renders it as an image blob, removes the old chart image on a specific slide, and inserts the fresh one in the same position.

Working with the chart as an image rather than trying to keep a live link intact means the refreshed slide behaves like any other image, which is far more reliable to automate than fighting with Slides' native chart-linking UI.

Once this pattern is set up, refreshing the deck before a weekly meeting becomes a single function call instead of a manual round trip between Sheets and Slides.

Need this built? Hire a Google Apps Script developer →

Sheet / project setup

ResourceName / valuePurpose
SpreadsheetSHEET_IDSource chart workbook
Chart index0getCharts()[0] on data tab
PresentationSLIDES_IDSlide receiving refreshed image
Slide index1Zero-based slide with chart image

What It Does

The script fetches a specific chart from a spreadsheet with sheet.getCharts(), converts it to a PNG blob, removes the previous chart image from a target slide, and inserts the new image at the same position and size.

Recording the position and size of the outgoing image before removing it is what makes the new chart land exactly where the old one used to be, rather than defaulting to the slide's top-left corner.

Prerequisites

The source spreadsheet needs at least one chart already created on a sheet, and you should know which index that chart occupies in the array returned by getCharts if there is more than one.

Identify the target slide by its position in the presentation and, if there is already a chart image there from a previous run, be ready for the script to remove it before adding the refreshed version.

Walkthrough

Set SPREADSHEET_ID, SLIDE_INDEX, and CHART_INDEX at the top of the script, then run refreshChartInSlides once to see the chart image appear on the target slide for the first time.

Update a value in the source spreadsheet that feeds the chart, run the function again, and confirm the image in Slides visibly reflects the new data rather than showing the stale version.

Check the position and size of the new chart image in Slides against the original manually placed chart to confirm the automated placement logic is matching correctly.

Edge Cases

If the target slide has no existing chart image because this is the very first run, the script skips the removal step gracefully and simply inserts the new image at a default position you specify.

Charts with a legend or title that changes size based on the data can shift the image's natural aspect ratio slightly between refreshes, so consider fixing the chart's dimensions in Sheets if pixel-perfect placement matters.

Testing

Run the refresh twice in a row without changing any data and confirm the slide still shows exactly one chart image rather than accumulating a new image on top of the old one each time.

Change the underlying data to something dramatically different, like doubling a value, and visually confirm the refreshed chart image reflects that change before trusting the automation for a real meeting deck.

Hardening

Tag the inserted image with a unique alt text description so the removal step can reliably find the chart image even if other unrelated images exist on the same slide.

Wrap the chart-fetch and image-insert calls in try/catch and fall back to leaving the existing image in place on failure, since a broken refresh should never leave the slide with no chart at all.

Variations

Trigger the refresh automatically on a time-driven trigger the morning of a recurring meeting instead of remembering to run it manually every week.

Extend the script to loop over multiple chart-and-slide pairs in one run when a single deck contains several charts that all need refreshing before a presentation.

refreshChartInSlides.gs

refreshChartInSlides renders a live Sheets chart as a PNG blob, removes the previously inserted chart image by matching its alt title, and inserts the fresh image at the same position.

// Refresh a Sheets chart image embedded on a specific Slides page
function refreshChartInSlides() {
  var SPREADSHEET_ID = 'REPLACE_WITH_SHEET_ID';
  var PRESENTATION_ID = 'REPLACE_WITH_PRESENTATION_ID';
  var SLIDE_INDEX = 0;
  var CHART_INDEX = 0;
  var ALT_TITLE = 'auto-chart';

  var ss = SpreadsheetApp.openById(SPREADSHEET_ID);
  var chart = ss.getSheets()[0].getCharts()[CHART_INDEX];
  var blob = chart.getAs('image/png');

  var presentation = SlidesApp.openById(PRESENTATION_ID);
  var slide = presentation.getSlides()[SLIDE_INDEX];
  var images = slide.getImages();

  var left = 50, top = 100, width = 500, height = 300;
  for (var i = 0; i < images.length; i++) {
    if (images[i].getTitle() === ALT_TITLE) {
      left = images[i].getLeft();
      top = images[i].getTop();
      width = images[i].getWidth();
      height = images[i].getHeight();
      images[i].remove();
      break;
    }
  }

  var inserted = slide.insertImage(blob, left, top, width, height);
  inserted.setTitle(ALT_TITLE);
}
  1. Line 11: getAs('image/png') renders the live chart object as a static image blob, which is what actually gets inserted into the slide.
  2. Line 19: Matching on a fixed alt-text title is how the script finds the previous chart image reliably instead of guessing by position.
  3. Line 20: Capturing the outgoing image's position and size before removing it is what lets the new chart land in exactly the same spot.
  4. Line 24: Removing the old image happens only after its geometry has been saved, so nothing about the layout is lost in the swap.
  5. Line 29: insertImage places the fresh chart using the captured coordinates, making the refresh visually seamless on the slide.
  6. Line 30: Re-tagging the new image with the same alt title keeps the next refresh able to find it in exactly the same way.

Deploy this example

  1. 01

    Open Apps Script

    In the bound spreadsheet: Extensions → Apps Script. For standalone projects, create one at script.google.com and link your Sheet by ID.

  2. 02

    Paste and save

    Add a .gs file, paste the code below, rename constants at the top (sheet names, column letters, API property keys), then save.

  3. 03

    Authorize once

    Run the main function from the editor. Accept OAuth scopes when prompted — triggers cannot run until authorization succeeds once.

  4. 04

    Add the trigger

    Triggers → Add trigger → choose the handler function and event (time-driven, on edit, or on form submit). Delete test triggers before production.

Before you run: update chart in slides

  • 1Source chart already created on a sheet, index noted
  • 2Target slide identified by its position in the presentation
  • 3Existing chart image tagged with a unique alt title
  • 4Position and size of the outgoing image captured before removal
  • 5Refresh tested after changing underlying spreadsheet data
  • 6Repeated runs confirmed not to duplicate the chart image

Frequently asked questions

Native chart links require manually clicking Update in the Slides UI, which this script automates away by rebuilding and swapping the image programmatically.

The removal step is skipped gracefully, and the new chart image is simply inserted at the default position you specify.

Yes, extend the script to loop over multiple chart-and-slide index pairs, refreshing each one in the same run as noted in the variations section.

The exported PNG looks visually identical to the chart in Sheets, though it becomes a static image rather than an editable chart object in Slides.

It looks for an image whose title matches a fixed alt-text tag rather than assuming it is always the first image on the slide.

Yes, attach a time-driven trigger scheduled for the morning of the meeting as suggested in the variations section.

Related examples

Want this wired into your real workflow?

I adapt these patterns to your Sheet structure, APIs, and triggers — deployed in your Google account. Fixed-scope quotes from $500 · free 30-min consult · quote within 24 hours.