Samples Stay organized with collections Save and categorize content based on your preferences.
This section presents acodelab you canuse to become familiar with the Google Sheets API. Also provided are a set of"recipe" examples that demonstrate how to translate an intended Google Sheetsaction into an API request.
Often there's more than one way to complete a given task with the API. Whenyou're deciding on how to approach a task, keep the following in mind:
- If you need to read or write cell values, the
spreadsheets.valuescollection is a better choice than thespreadsheetscollection. The former's interface is easier to use for simple read/writeoperations. Wherever possible, use the batch methods(
spreadsheet.batchUpdate,spreadsheet.values.batchGet,andspreadsheet.values.batchUpdate)to bundle multiple requests into a single method call. Using these batchmethods improves efficiency as they:- Reduce client HTTP overhead.
- Reduce the number of queries made.
- Reduce the number of revisions on the doc.
- Ensure atomicity of all the changes in the batch.
Recipes
The examples listed in this section demonstrate how to express common actions inSheets as Sheets API v4 requests.
These examples are presented in the form of HTTP requests to be languageneutral. To learn how to implement Sheets API request protocols in aspecific language using Google API client libraries, see theRead & write cellvalues andUpdatespreadsheets guides.
Recipes in this section are divided into the following categories:
- Basic reading—Recipes thatshow how to read values from a sheet.
- Basic writing—Recipes thatshow how to write values to a sheet.
- Basic formatting—Recipesthat show how to change the appearance of sheets and cells.
- Charts—Recipes that show howto create and alter charts in a sheet.
- Conditional formatting—Recipes that show how to alter cell appearance based on conditions.
- Data operations—Recipes thatshow how to create, move, and manipulate data in a spreadsheet.
- Named & protectedranges—Recipes that show how tocreate, update, and remove named and protected ranges in a spreadsheet.
- Pivot tables—Recipesthat show how to create pivot tables in a sheet.
- Row & columnoperations—Recipes that showhow to add, remove, and move rows and columns, and update their properties.
- Sheet operations—Recipes thatshow how to create, clear, copy, and delete sheets, and also control theirproperties.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.