[GAS Beginner Series #69] Embed Spreadsheet Charts into Slides: Complete Slide.insertSheetsChart() Guide

In our previous lesson (#68), we learned how to use Slide.insertTable() to automatically generate a “Project Revenue & Cost Trend Table” inside Google Slides! Displaying figures neatly in a table is wonderful, but when presenting at board meetings or monthly reviews, having visual charts that convey insights at a glance is absolutely essential.

However, do you find yourself dealing with frustrations like these when preparing monthly reports?

  • “Copying and pasting sales charts from Google Sheets to Google Slides every month is so tedious…”
  • “When pasting manually, the chart’s position and size shift slightly each month, making the slides look messy…”
  • “The source data changed, but I forgot to update the chart in the slide and ended up presenting outdated numbers…”

By mastering Slide.insertSheetsChart(), which we will explore today, you can instantly embed charts created in Google Sheets (such as sales trends and target achievement rates) right into the exact target position on a slide with just one click!

Writing practical code to automate a monthly report for our Sapporo office, this guide will cover everything from basic operations to fine-tuning dimensions and positions down to the point, as well as common beginner pitfalls—explained more clearly and thoroughly than anywhere else!

1. What Is Slide.insertSheetsChart() in Google Apps Script?

Slide.insertSheetsChart() is a Google Apps Script method used to retrieve an existing chart (an EmbeddedChart object) from a Google Sheet and embed it onto a specific page (a Slide object) in Google Slides.

Basic Code Syntax (Two Overloads)

insertSheetsChart() primarily offers two syntax patterns (overloads).

Pattern 1: Simple Insertion at the Default Position (Near Top-Left)

var sheetsChart = slide.insertSheetsChart(sourceChart);
  • sourceChart: The embedded chart object (EmbeddedChart) retrieved from Google Sheets.
  • Characteristics: Places the chart on the slide at a default size and position without requiring explicit coordinates.

Pattern 2: Insertion with Custom Position (Coordinates) and Size (Width & Height) [Ideal for Real Projects!]

var sheetsChart = slide.insertSheetsChart(sourceChart, left, top, width, height);
  • left: Distance from the left edge of the slide (in points: pt).
  • top: Distance from the top edge of the slide (in points: pt).
  • width: Width of the chart (in points: pt).
  • height: Height of the chart (in points: pt).
  • Characteristics: Allows you to place the chart neatly and precisely at your desired dimensions and location.

2. Understanding Slides and Charts Using the “House, Room, Furniture” Analogy

Let’s use our familiar “House, Room, and Furniture” analogy from this series to organize the structure of this cross-application workflow between Sheets and Slides!

In lessons #2 through #4, we covered the hierarchy of Google Sheets, and starting from #61, we explored how to manipulate Google Slides. Today’s process is a collaborative workflow crossing between two separate houses (files).

ConceptReal-World AnalogyGoogle Sheets TargetGoogle Slides Target
Entire File (House)HQ Building / Branch BuildingSpreadsheetApp.openById()SlidesApp.openById()
Individual Page (Room)Meeting Room or Private OfficeSpreadsheet.getSheetByName()Presentation.getSlides()[0]
Element / Item (Furniture)Framed Poster or Wall NoticeSheet.getCharts()[0] (Source Chart)Slide.insertSheetsChart() (Embedded Chart)

Taking a favorite framed chart (furniture) out of your Spreadsheet “first house” and mounting it perfectly on the wall of a designated room (slide page) in your Slides “second house”—that is exactly what Slide.insertSheetsChart() does!

3. STEP 1: Preparation! Setting Up Your Spreadsheet and Presentation

Now, let’s prepare the practice files we need to run our GAS script!

Our sample project today is the “Sapporo Office Monthly Sales Report.”

1. Prepare the Spreadsheet (Create a Chart)

  1. Create a new Google Spreadsheet in Google Drive and name the file “[Sapporo Office] Monthly Sales Data”.
  2. Rename the active sheet tab to “Sales Trends”.
  3. Enter the following sample table data:
Column A (Month)Column B (Sales: 10k JPY)Column C (Target: 10k JPY)
April12001000
May13501200
June11001200
July15001300
August16801400
  1. Select the range A1:C6 and click Insert > Chart from the top menu.
  2. Confirm that a column chart or line chart is generated on the sheet.

💡 Note Down Your Spreadsheet ID!

Copy the alphanumeric ID from your browser’s address bar (the highlighted section below) and paste it into a notepad for later use:

https://docs.google.com/spreadsheets/d/ 1A2B3C4D5E6F7G8H9I0J_EXAMPLE_SS_ID /edit

2. Prepare the Google Slide Deck

  1. Create a new Google Slides presentation in Google Drive and name it “Sapporo Office Monthly Performance Report Presentation”.
  2. On the first slide, enter “Sapporo Office Monthly Sales Topics” into the title placeholder.

💡 Note Down Your Slide ID Too!

Copy the presentation ID from the URL and save it as well:

https://docs.google.com/presentation/d/ 9Z8Y7X6W5V4U3T2S1R0Q_EXAMPLE_SLIDE_ID /edit

You are all set!

4. STEP 2: [Hands-On] Automatically Embed the Sheets Chart into Your Slide!

Now that your files are ready, open the Apps Script editor (either container-bound to your spreadsheet/presentation or as a standalone script) and let’s write the automation!

(We will use the openById approach so it can be executed from anywhere.)

1. Open the Script Editor and Paste the Code

Open the GAS editor, clear any existing placeholder code, and paste the following script.

* Make sure to replace SS_ID and SLIDE_ID with your own copied IDs!

function embedSapporoSalesChart() {
  // -----------------------------------------------------------------
  // 1. [Sheets Side] Retrieve the source chart (EmbeddedChart)
  // -----------------------------------------------------------------
  // Open the spreadsheet by its ID
  var ssId = "1A2B3C4D5E6F7G8H9I0J_EXAMPLE_SS_ID"; // ← Replace with your Spreadsheet ID
  var ss = SpreadsheetApp.openById(ssId);
  
  // Get the "Sales Trends" sheet
  var sheet = ss.getSheetByName("Sales Trends");
  
  // Retrieve all charts existing on the sheet (returned as an array)
  var charts = sheet.getCharts();
  
  // Safety check: confirm a chart actually exists
  if (charts.length === 0) {
    Logger.log("Error: No charts found on the specified sheet.");
    return;
  }
  
  // Target the first chart (index 0)
  var sourceChart = charts[0];

  // -----------------------------------------------------------------
  // 2. [Slides Side] Get the target slide page
  // -----------------------------------------------------------------
  // Open the presentation by its ID
  var presentationId = "9Z8Y7X6W5V4U3T2S1R0Q_EXAMPLE_SLIDE_ID"; // ← Replace with your Presentation ID
  var presentation = SlidesApp.openById(presentationId);
  
  // Get the first slide (index 0)
  var targetSlide = presentation.getSlides()[0];

  // -----------------------------------------------------------------
  // 3. [Main Action] Embed the Sheets chart into the slide!
  // -----------------------------------------------------------------
  var insertedChart = targetSlide.insertSheetsChart(sourceChart);

  // Output execution result to the log (using Logger.log from Lesson 1)
  Logger.log("Successfully embedded the Sapporo office monthly sales chart into the slide!");
}

2. Line-by-Line Code Breakdown

Let’s break down the essential points line by line for beginners!

  • var charts = sheet.getCharts();
    • A method belonging to the Sheet object. It collects all embedded charts on the sheet and returns them as an array (list).
  • var sourceChart = charts[0];
    • Extracts the first EmbeddedChart object in the array (remember, counting starts at 0 in programming!).
  • var presentation = SlidesApp.openById(presentationId);
    • The SlidesApp.openById() method we learned in Lesson 61! It opens the target presentation file.
  • var targetSlide = presentation.getSlides()[0];
    • Selects the first slide page out of all slides contained within the presentation.
  • targetSlide.insertSheetsChart(sourceChart);
    • Our spotlight method today! It automatically pastes the spreadsheet chart (sourceChart) directly onto the selected slide (targetSlide).

3. Save and Run the Script!

  1. Click the Save icon (floppy disk) at the top of the editor.
  2. Verify that the selected function is set to embedSapporoSalesChart, then click Run.
  3. If this is your first time running it, Google’s authorization prompt will appear. Follow the on-screen steps to grant the necessary permissions.
  4. Open your Google Slides file to inspect the result!

[Execution Result]

If the “Sapporo Office Monthly Sales Chart” generated from Google Sheets appears embedded cleanly in the center of your first slide, your execution is a complete success!

5. STEP 3: [Advanced Practical Application] Specifying Coordinates and Dimensions Precisely

Once you feel confident inserting charts at the default location, let’s step up to the most useful technique in production: explicitly setting positioning coordinates and dimensions!

A standard 16:9 Google Slide typically measures 720 points wide by 405 points high.

For instance, if your layout requires placing a chart on the left half of the slide and a narrative text box on the right, you need to calculate and pass the exact coordinates beforehand.

Custom Coordinate & Size Code Example

function embedSapporoSalesChartWithPosition() {
  var ss = SpreadsheetApp.openById("1A2B3C4D5E6F7G8H9I0J_EXAMPLE_SS_ID");
  var sourceChart = ss.getSheetByName("Sales Trends").getCharts()[0];
  
  var presentation = SlidesApp.openById("9Z8Y7X6W5V4U3T2S1R0Q_EXAMPLE_SLIDE_ID");
  var targetSlide = presentation.getSlides()[0];

  // -----------------------------------------------------------------
  // Define placement coordinates and dimensions in points (pt)
  // -----------------------------------------------------------------
  var left = 40;     // Distance from left margin (40pt)
  var top = 100;     // Distance from top margin (100pt: beneath the title)
  var width = 380;   // Chart width (380pt)
  var height = 250;  // Chart height (250pt)

  // Insert the chart at exact dimensions by passing 5 arguments!
  var positionedChart = targetSlide.insertSheetsChart(
    sourceChart, 
    left, 
    top, 
    width, 
    height
  );

  Logger.log("Chart placed cleanly at specified coordinates and dimensions!");
}

Running this function places the chart seamlessly onto the left side of the slide. In the remaining right-hand space (around left: 440), you can insert an explanatory text box using Slide.insertTextBox() from Lesson 66 to build a polished, executive-ready presentation slide!

6. How Linked Sheets Charts Work and How to Refresh Them

Charts embedded via Slide.insertSheetsChart() possess a remarkable capability:

They remain dynamically linked in real time to the source Google Sheet!

Advantages of Linked Sheets Charts

When you select the inserted chart on a slide, a small “Linked chart options” icon appears at the top right.

When next month’s sales numbers change in the spreadsheet or someone updates the chart’s styling (colors or titles), clicking “Update” in Slides will immediately swap in the latest chart graphic without re-inserting anything manually.

How to Programmatically Refresh Embedded Charts with GAS

When building end-to-end automation pipelines, calling the .refresh() method on a slide’s SheetsChart object synchronizes it with the latest data automatically—no manual button clicking required!

// Example: Refreshing all embedded Sheets charts on a slide
var sheetsCharts = targetSlide.getSheetsCharts();
for (var i = 0; i < sheetsCharts.length; i++) {
  sheetsCharts[i].refresh(); // Updates the chart with the latest Spreadsheet data!
}

7. Top 5 Beginner Traps and How to Solve Them

Here are five common traps and errors beginners encounter when working with Slide.insertSheetsChart(). Review these now so you can avoid spending hours debugging!

Trap 1: Forgetting [0] After sheet.getCharts()

✕ Incorrect Code

var sourceChart = sheet.getCharts(); // Passing the entire array directly!
targetSlide.insertSheetsChart(sourceChart);

🚨 Error Message

Exception: The parameters (JavaScript Array) don't match the method signature for Slide.insertSheetsChart.

💡 Solution

sheet.getCharts() returns an array (a collection) of charts, not a single chart. To target the first chart, always specify index [0], like sheet.getCharts()[0].

Trap 2: Calling insertSheetsChart Directly on the Presentation Object

✕ Incorrect Code

var presentation = SlidesApp.openById(presentationId);
// Trying to insert directly into the house (Presentation) instead of a room (Slide)!
presentation.insertSheetsChart(sourceChart);

🚨 Error Message

TypeError: presentation.insertSheetsChart is not a function

💡 Solution

insertSheetsChart() is a dedicated method belonging to the Slide object (individual slide page / room). Make sure to first retrieve the specific slide using presentation.getSlides()[0] before calling the method.

Trap 3: No Charts Exist on the Target Sheet (charts.length === 0)

If a chart has not been created on the spreadsheet or if the sheet name is mistyped, attempting to read charts[0] triggers an immediate error.

🚨 Error Message

TypeError: Cannot read property '0' of undefined (or charts[0] evaluates to undefined)

💡 Solution

Adding a simple guard clause before executing chart operations keeps your script safe and informative:

if (charts.length === 0) {
  Logger.log("Error: No charts found on the specified sheet. Please verify your spreadsheet.");
  return; // Safely exit execution
}

Trap 4: File ID Typos and Permission Errors

🚨 Error Message

Exception: Document 1A2B3C... is missing (or permission denied).

💡 Solution

Check that the ID string passed to openById("ID") does not accidentally include the surrounding URL (e.g., https://...) or stray whitespace. Also, ensure the logged-in Google account has edit permissions for both files.

Trap 5: Chart Dimensions Exceeding the Slide Canvas

Passing excessive values like 1000 for width or height causes the chart to overflow outside the visible slide boundaries.

💡 Solution

As noted earlier, a standard 16:9 slide canvas is 720pt wide by 405pt high.

As a safe guideline, keep your dimensions around 300pt–500pt for width and 200pt–300pt for height to achieve a balanced, comfortable layout!

8. Summary and Next Lesson Preview

In this lesson, we explored a comprehensive guide to Slide.insertSheetsChart() for automating spreadsheet chart embeds into Google Slides!

Key Takeaways for Today

  1. Slide.insertSheetsChart(sourceChart) lets you embed Google Sheets charts into slides in an instant!
  2. Retrieve the EmbeddedChart object from Sheets using sheet.getCharts()[0].
  3. When you need custom layouts, use insertSheetsChart(sourceChart, left, top, width, height)!
  4. Embedded charts stay linked to the spreadsheet, allowing you to update them automatically via .refresh().

With these techniques in hand, you are completely free from the hassle of manual copy-pasting and repetitive alignment adjustments!

What’s Next?

Once you know how to embed dynamic charts, the next thing you will want to add to your presentations is real photographic imagery—such as photos of events or team activities from our Sapporo office!

In our next tutorial (Lesson 70), we will dive into Slide.insertImage()!

We will explain how to automatically insert image files stored in Google Drive directly onto your slides, so stay tuned!