Advanced Sheets Service  |  Apps Script  |  Google for Developers (2024)

Stay organized with collections Save and categorize content based on your preferences.

The Advanced Sheets service lets you access the Sheets API usingApps Script. Much like Apps Script's built-in Google Sheets API service,this API allows scripts to read, edit, format and present data in Google Sheets.In most cases, the built-in service is easier to use, but thisadvanced service provides a few extra features.

Reference

For detailed information on this service, see thereference documentation for the Sheets API.Like all advanced services in Apps Script, the advanced Sheets service uses thesame objects, methods, and parameters as the public API. For more information, see How method signatures are determined.

To report issues and find other support, see theSheets support guide.

Sample code

The sample code below uses version 4 of the API;this is the only version of the Sheets API currently available as anadvanced service in Apps Script.

Read values from a range

The following example demonstrates how to read data values from a specifiedrange in a sheet with the Sheets advanced service. It is equivalent to theRead a single rangerecipe sample.

advanced/sheets.gs

/** * Read a range (A1:D5) of data values. Logs the values. * @param {string} spreadsheetId The spreadsheet ID to read from. * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get */function readRange(spreadsheetId = yourspreadsheetId) { try { const response = Sheets.Spreadsheets.Values.get(spreadsheetId, 'Sheet1!A1:D5'); if (response.values) { console.log(response.values); return; } console.log('Failed to get range of values from spreadsheet'); } catch (e) { // TODO (developer) - Handle exception console.log('Failed with error %s', e.message); }}

Write values to multiple ranges

The following example demonstrates how to write data to different, disjointranges in a sheet with one request. It is equivalent to theWrite to multiple rangesrecipe sample.

advanced/sheets.gs

/** * Write to multiple, disjoint data ranges. * @param {string} spreadsheetId The spreadsheet ID to write to. * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchUpdate */function writeToMultipleRanges(spreadsheetId = yourspreadsheetId) { // Specify some values to write to the sheet. const columnAValues = [ ['Item', 'Wheel', 'Door', 'Engine'] ]; const rowValues = [ ['Cost', 'Stocked', 'Ship Date'], ['$20.50', '4', '3/1/2016'] ]; const request = { 'valueInputOption': 'USER_ENTERED', 'data': [ { 'range': 'Sheet1!A1:A4', 'majorDimension': 'COLUMNS', 'values': columnAValues }, { 'range': 'Sheet1!B1:D2', 'majorDimension': 'ROWS', 'values': rowValues } ] }; try { const response = Sheets.Spreadsheets.Values.batchUpdate(request, spreadsheetId); if (response) { console.log(response); return; } console.log('response null'); } catch (e) { // TODO (developer) - Handle exception console.log('Failed with error %s', e.message); }}

Add a new sheet

The following example demonstrates how to create a new sheet with specificsize and tab color. It is equivalent to theAdd a sheet recipe sample.

advanced/sheets.gs

/** * Add a new sheet with some properties. * @param {string} spreadsheetId The spreadsheet ID. * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/batchUpdate */function addSheet(spreadsheetId = yourspreadsheetId) { const requests = [{ 'addSheet': { 'properties': { 'title': 'Deposits', 'gridProperties': { 'rowCount': 20, 'columnCount': 12 }, 'tabColor': { 'red': 1.0, 'green': 0.3, 'blue': 0.4 } } } }]; try { const response = Sheets.Spreadsheets.batchUpdate({'requests': requests}, spreadsheetId); console.log('Created sheet with ID: ' + response.replies[0].addSheet.properties.sheetId); } catch (e) { // TODO (developer) - Handle exception console.log('Failed with error %s', e.message); }}

Create a pivot table

The following example demonstrates how to create a pivot table from source data.It is equivalent to the Add a pivot tablerecipe sample.

advanced/sheets.gs

/** * Add a pivot table. * @param {string} spreadsheetId The spreadsheet ID to add the pivot table to. * @param {string} pivotSourceDataSheetId The sheet ID to get the data from. * @param {string} destinationSheetId The sheet ID to add the pivot table to. * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/batchUpdate */function addPivotTable( spreadsheetId = yourspreadsheetId, pivotSourceDataSheetId= yourpivotSourceDataSheetId, destinationSheetId= yourdestinationSheetId) { const requests = [{ 'updateCells': { 'rows': { 'values': [ { 'pivotTable': { 'source': { 'sheetId': pivotSourceDataSheetId, 'startRowIndex': 0, 'startColumnIndex': 0, 'endRowIndex': 20, 'endColumnIndex': 7 }, 'rows': [ { 'sourceColumnOffset': 0, 'showTotals': true, 'sortOrder': 'ASCENDING', 'valueBucket': { 'buckets': [ { 'stringValue': 'West' } ] } }, { 'sourceColumnOffset': 1, 'showTotals': true, 'sortOrder': 'DESCENDING', 'valueBucket': {} } ], 'columns': [ { 'sourceColumnOffset': 4, 'sortOrder': 'ASCENDING', 'showTotals': true, 'valueBucket': {} } ], 'values': [ { 'summarizeFunction': 'SUM', 'sourceColumnOffset': 3 } ], 'valueLayout': 'HORIZONTAL' } } ] }, 'start': { 'sheetId': destinationSheetId, 'rowIndex': 49, 'columnIndex': 0 }, 'fields': 'pivotTable' } }]; try { const response = Sheets.Spreadsheets.batchUpdate({'requests': requests}, spreadsheetId); // The Pivot table will appear anchored to cell A50 of the destination sheet. } catch (e) { // TODO (developer) - Handle exception console.log('Failed with error %s', e.message); }}

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-08-29 UTC.

Advanced Sheets Service  |  Apps Script  |  Google for Developers (2024)

FAQs

What is the difference between Google Sheets API and Google Apps Script? ›

Much like Apps Script's built-in Google Sheets API service, this API allows scripts to read, edit, format and present data in Google Sheets. In most cases, the built-in service is easier to use, but this advanced service provides a few extra features. This is an advanced service that must be enabled before use.

What language does Google Sheets app script use? ›

Google Apps Script is a rapid application development platform that makes it fast and easy to create business applications that integrate with Google Workspace. You write code in modern JavaScript and have access to built-in libraries for favorite Google Workspace applications like Gmail, Calendar, Drive, and more.

Can you run scripts on Google Sheets app? ›

A custom menu lets you extend the user interface of Google Sheets to make it easy for users to run scripts. Each menu item is linked to a function in your script and this function will be run whenever that menu item is selected by the user.

How do I implement an app script in Google Sheets? ›

Click Extensions > Apps Script to open the script editor, then copy the script text from the original spreadsheet and paste it into the script editor of another spreadsheet. Make a copy of the spreadsheet that contains the custom function by clicking File > Make a copy.

Is Google Apps script similar to VBA? ›

VBA merges similar capabilities to Google Forms, Apps Script, add-on-type user interfaces, and the object model into one platform. You need some or all of the Apps Script–related components to achieve the same thing.

Is Google app Script worth learning? ›

For most users, Apps Script is very good for small scale solutions, but if your project would either be used more widely than just you, or would be used for larger scale or business critical processes, you might need to take extra things into consideration.

Can I run python in Google Apps Script? ›

Your Python application runs and calls the Google Apps Script API. Authorization information is stored in the file system, so the next time you run the sample code, you aren't prompted for authorization.

How to speed up Google Apps Script? ›

Use batch operations

Alternating read and write commands is slow. To speed up a script, read all data into an array with one command, perform any operations on the data in the array, and write the data out with one command.

What is the most common programming language to automate Google Sheets? ›

Google Sheets Automation with Apps Script. Apps Script is a scripting language based on JavaScript that allows users to customize and automate Google Workspace applications, including Google Sheets.

What can you do with a Google Apps Script? ›

Apps Script empowers users to focus on what matters and get the most out of Google Workspace by automating time-consuming, tedious tasks, creating integrations that connect the applications they use every day and adding functionality or customizations where and when needed.

Is Google Apps Script JavaScript? ›

Apps Script is a cloud-based JavaScript platform powered by Google Drive that lets you integrate with and automate tasks across Google products.

Is Google App script free? ›

Do I need to pay for Google Workspace to use Apps Script? No. All you need is a Gmail account to begin building with Apps Script.

How do I automate Google Apps Script? ›

Getting started with Google App Scripts

We can also create a script directly from the Google tool to which we want to associate it, in the case of Sheets we can do it by clicking on Tools → Script editor. This will open a development environment in the cloud where the script code can be written and executed directly.

How do I bind an app script in Google Sheets? ›

To create a bound script in Google Docs, Sheets, or Slides, open a document in Docs, a spreadsheet in Sheets, or a presentation in Slides and click Extensions > Apps Script. To reopen the script in the future, do the same thing or open the script from the Apps Script dashboard.

Can you code in Google Sheets? ›

Google Sheets also comes with a coding platform called Apps Script that makes it super easy to build useful applications.

What is the difference between API and Script in Google Apps? ›

The API provides methods to list existing processes and gather information about them, such as type and current status. scripts — The endpoint that provides methods to remotely execute Apps Script functions.

What is Google Sheets API? ›

The Google Sheets API is a RESTful interface that lets you read and modify a spreadsheet's data. The most common uses of this API include the following tasks: Create spreadsheets. Read and write spreadsheet cell values. Update spreadsheet formatting.

What is the purpose of Google Apps script? ›

Apps Script empowers users to focus on what matters and get the most out of Google Workspace by automating time-consuming, tedious tasks, creating integrations that connect the applications they use every day and adding functionality or customizations where and when needed.

Do I need to pay for Google Sheets API? ›

All use of the Google Sheets API is available at no additional cost.

Top Articles
The top grossing mobile games of 2023 - Mobilegamer.biz
How to Determine Risk Tolerance for Investing - Experian
Star Wars Mongol Heleer
Greedfall Console Commands
Western Union Mexico Rate
DL1678 (DAL1678) Delta Historial y rastreo de vuelos - FlightAware
Call Follower Osrs
10000 Divided By 5
What Happened To Father Anthony Mary Ewtn
A Fashion Lover's Guide To Copenhagen
13 The Musical Common Sense Media
Ktbs Payroll Login
Tight Tiny Teen Scouts 5
Full Range 10 Bar Selection Box
Ivegore Machete Mutolation
Costco Gas Foster City
Q Management Inc
Ukc Message Board
Full Standard Operating Guideline Manual | Springfield, MO
zom 100 mangadex - WebNovel
67-72 Chevy Truck Parts Craigslist
Jeffers Funeral Home Obituaries Greeneville Tennessee
What Equals 16
Bolsa Feels Bad For Sancho's Loss.
Foodsmart Jonesboro Ar Weekly Ad
Impact-Messung für bessere Ergebnisse « impact investing magazin
January 8 Jesus Calling
1979 Ford F350 For Sale Craigslist
27 Modern Dining Room Ideas You'll Want to Try ASAP
Dexter Gomovies
The Fabelmans Showtimes Near Baton Rouge
Santa Barbara Craigs List
Craftsman Yt3000 Oil Capacity
Abga Gestation Calculator
Devargasfuneral
New York Rangers Hfboards
Srg Senior Living Yardi Elearning Login
Maxpreps Field Hockey
Craigslist List Albuquerque: Your Ultimate Guide to Buying, Selling, and Finding Everything - First Republic Craigslist
Wattengel Funeral Home Meadow Drive
Wsbtv Fish And Game Report
Aita For Announcing My Pregnancy At My Sil Wedding
Achieving and Maintaining 10% Body Fat
Mynord
Skyward Cahokia
Ohio Road Construction Map
Workday Latech Edu
4Chan Zelda Totk
Dolce Luna Italian Restaurant & Pizzeria
Craigslist Sarasota Free Stuff
Lsreg Att
How to Find Mugshots: 11 Steps (with Pictures) - wikiHow
Latest Posts
Article information

Author: Arielle Torp

Last Updated:

Views: 5954

Rating: 4 / 5 (41 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Arielle Torp

Birthday: 1997-09-20

Address: 87313 Erdman Vista, North Dustinborough, WA 37563

Phone: +97216742823598

Job: Central Technology Officer

Hobby: Taekwondo, Macrame, Foreign language learning, Kite flying, Cooking, Skiing, Computer programming

Introduction: My name is Arielle Torp, I am a comfortable, kind, zealous, lovely, jolly, colorful, adventurous person who loves writing and wants to share my knowledge and understanding with you.