What is SpreadsheetApp in Google Sheets?

SpreadsheetApp is the main Apps Script service for talking to Google Sheets. It lets your script open the active spreadsheet, grab sheets by name, read cells, write values, and change formatting. Almost every Sheets automation starts with SpreadsheetApp.getActiveSpreadsheet().

When to use it

Use SpreadsheetApp whenever your script reads or writes grid data: custom menus, triggers, web apps, mail merges, or batch updates that formulas cannot handle cleanly.

When to skip it

Skip SpreadsheetApp when you only need to send email, fetch a URL, or store a setting with no sheet access. Other services like MailApp or PropertiesService handle those jobs.

How it works

  1. 1

    Call SpreadsheetApp.getActiveSpreadsheet() in a bound script tied to the open file.

  2. 2

    Use getSheetByName('TabName') or getSheets() to target the right tab.

  3. 3

    Get a range with getRange('A1:D10') or getActiveRange(), then read or write values.

  4. 4

    Open another file by ID with openById when the script is authorized for that spreadsheet.

  5. 5

    Flush changes with SpreadsheetApp.flush() when you need pending writes visible before the next step.

  6. 6

    Check Executions and use Logger.log while testing so errors in range names are obvious.

Examples in Google Sheets

Summary on open

onOpen uses SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Dashboard') and sets A1 to today's date.

Copy rows to archive

Read all values from the Data tab, filter rows where status is Closed, and append them to an Archive sheet in the same file.

Open a master workbook

SpreadsheetApp.openById('abc123') opens a shared master sheet and reads a lookup table into an array for validation.

Build this without starting from a blank cell

Use a Better Sheets tool for SpreadsheetApp, then watch a walkthrough when you want the full pattern.

Better Sheets resources

Common mistakes

  • Calling getActiveSpreadsheet() in a standalone script with no active sheet context.
  • Using getSheetByName without checking for null when the tab was renamed.
  • Reading the entire sheet with getDataRange() on huge tabs, slowing every run.
  • Hard-coding spreadsheet IDs in many places instead of one Settings tab or PropertiesService.
  • Forgetting that openById needs the script to have access to that file.

Frequently asked questions

What is the difference between getActiveSpreadsheet and openById?
getActiveSpreadsheet targets the file bound to the script or currently open. openById opens any spreadsheet the script can access by its ID from the URL.
Can SpreadsheetApp create a new sheet?
Yes. Call insertSheet on the spreadsheet object to add a tab, then write headers and data.
Does SpreadsheetApp work in web apps?
Yes. Server functions in a web app use SpreadsheetApp the same way, subject to deployment permissions.
How do I get the spreadsheet ID?
Copy it from the sheet URL between /d/ and /edit. Store it in Script Properties for standalone projects.
Can I delete rows with SpreadsheetApp?
Yes. Use deleteRow, deleteRows, or clearContent on ranges. Test on a copy first because there is no script Undo.
Why does my script say Cannot find spreadsheet?
The ID may be wrong, the file was deleted, or the account running the script lacks permission to open it.
Is SpreadsheetApp the same as the Sheets API?
No. SpreadsheetApp is built into Apps Script. The Sheets API is a separate HTTP API often used from outside Google.
Can macros use SpreadsheetApp?
Recorded macros generate SpreadsheetApp calls. You can edit and extend that code in the Script Editor.

Related Tutorials

Watch how SpreadsheetApp works

Browse more tutorials
From Sheet to Script And Back Again - Learn to Code In Google Sheets Part 3

From Sheet to Script And Back Again - Learn to Code In Google Sheets Part 3

In this video, I'm going to share with you how to go basically from shee...
The First Thing I Do When Starting a Google Sheet

The First Thing I Do When Starting a Google Sheet

Are you tired of the default look of your Google Sheets? In this video, ...
Embed a Number in a Website from a Google Sheet

Embed a Number in a Website from a Google Sheet

Ever wanted to display some data from a google sheet on your site? Witho...
MAKE Your Google Sheets Add-on WORK

MAKE Your Google Sheets Add-on WORK

In this section of the Add-on course we'll be making the apps script wor...
5 Ways To Use Google Sheets for Advanced Project Management

5 Ways To Use Google Sheets for Advanced Project Management

Here are 5 advanced ways to manage projects inside of Google Sheets Man...
Spreadsheet Automation 101 Lesson 1: GetValue - Introduction to SpreadsheetApp

Spreadsheet Automation 101 Lesson 1: GetValue - Introduction to SpreadsheetApp

Learn to write codes in Apps Script. Understand what SpreadsheetApp is u...

Related blog posts

Guides that explain SpreadsheetApp in more depth.

Browse the blog

Related glossary terms

Done reading about SpreadsheetApp?

Membership unlocks 636+ tutorials, unlimited generators, and every template. Practical lessons. Zero fluff.

Need this once

Jump to a free tool or a single tutorial for this topic.

Learning Sheets for real

Unlock the full library, generators, and templates with membership.