Sheet operations  |  Google Sheets  |  Google for Developers (2024)

The Google Sheets API lets you create, clear, copy, and delete sheets, and alsocontrol their properties. The examples on this page illustrate how you canachieve some common Sheets operations with theSheets API.

These examples are presented in the form of HTTP requests to be languageneutral. To learn how to implement a batch update in different languages usingthe Google API client libraries, see Updatespreadsheets.

In these examples, the placeholders SPREADSHEET_ID and SHEET_IDindicates where you would provide those IDs. You can find the spreadsheetID in the spreadsheet URL. You can getthe sheet ID by using thespreadsheets.get method. Theranges are specified using A1 notation. Anexample range is Sheet1!A1:D5.

Add a sheet

The followingspreadsheets.batchUpdatecode sample shows how to use theAddSheetRequestto add a sheet to a spreadsheet, while also setting the title, grid size, andtab color.

The response consists of aAddSheetResponse,which contains an object with the created sheet's properties (such as itsSHEET_ID).

The request protocol is shown below.

POST https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID:batchUpdate
{ "requests": [ { "addSheet": { "properties": { "title": "Deposits", "gridProperties": { "rowCount": 20, "columnCount": 12 }, "tabColor": { "red": 1.0, "green": 0.3, "blue": 0.4 } } } } ]}

Clear a sheet of all values while preserving formats

The followingspreadsheets.batchUpdatecode sample shows how to use theUpdateCellsRequestto remove all values from a sheet while leaving the formatting unaltered.

Specifying theuserEnteredValue fieldwithout a corresponding value is interpreted as an instruction to clear valuesin the range. This setting can be used with other fields as well. For example,changing the fields value touserEnteredFormat removesall formatting supported by the Sheets APIfrom the sheet, but leaves the cell values unaltered.

The request protocol is shown below.

POST https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID:batchUpdate
{ "requests": [ { "updateCells": { "range": { "sheetId": SHEET_ID }, "fields": "userEnteredValue" } } ]}

Copy a sheet from one spreadsheet to another

The followingspreadsheet.sheets.copyTocode sample shows how to copy a single sheet specified by SHEET_IDfrom one spreadsheet to another spreadsheet.

The TARGET_SPREADSHEET_ID variable in the request body specifies thedestination spreadsheet. The copy retains all values, formatting, formulas, andother properties of the original. The title of the copied sheet is set to "Copyof [original sheet title]".

The response consists of aSheetPropertiesobject describing the properties of the created sheet.

POST https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID/sheets/SHEET_ID:copyTo
{ "destinationSpreadsheetId": "TARGET_SPREADSHEET_ID"}

Delete a sheet

The followingspreadsheets.batchUpdatecode sample shows how to use theDeleteSheetRequestto delete a sheet specified by SHEET_ID.

The request protocol is shown below.

POST https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID:batchUpdate
{ "requests": [ { "deleteSheet": { "sheetId": SHEET_ID } } ]}

Read sheet data

The followingspreadsheets.get code sampleshows how to get sheet property informationfrom a spreadsheet, specified by SHEET_IDand SPREADSHEET_ID. This method is often used to determine themetadata of sheets within a specific spreadsheet, so additional operations cantarget those sheets. The fields query parameter specifies only sheet propertydata should be returned (as opposed to cell value data or data related to theentire spreadsheet).

GET https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID?&fields=sheets.properties

The response consists of aSpreadsheetresource, which contains aSheet object withSheetPropertieselements. If a given response field is set to the default value, it's omittedfrom the response.

{ "sheets": [ { "properties": { "sheetId": SHEET_ID, "title": "Sheet1", "index": 0, "sheetType": "GRID", "gridProperties": { "rowCount": 100, "columnCount": 20, "frozenRowCount": 1 } "tabColor": { "blue": 1.0 } }, ... ],}
Sheet operations  |  Google Sheets  |  Google for Developers (2024)
Top Articles
Record a loan for an asset in QuickBooks Online
X1 Credit Card
Chris Provost Daughter Addie
Craglist Oc
Otis Department Of Corrections
Hotels Near 500 W Sunshine St Springfield Mo 65807
Wfin Local News
What is international trade and explain its types?
Jefferson County Ky Pva
Toonily The Carry
FIX: Spacebar, Enter, or Backspace Not Working
ATV Blue Book - Values & Used Prices
Athens Bucket List: 20 Best Things to Do in Athens, Greece
Explore Top Free Tattoo Fonts: Style Your Ink Perfectly! 🖌️
Jackson Stevens Global
065106619
N2O4 Lewis Structure & Characteristics (13 Complete Facts)
Leader Times Obituaries Liberal Ks
History of Osceola County
Lehmann's Power Equipment
Costco Great Oaks Gas Price
Violent Night Showtimes Near Century 14 Vallejo
Pasco Telestaff
Shadbase Get Out Of Jail
Rapv Springfield Ma
Shoe Station Store Locator
Workshops - Canadian Dam Association (CDA-ACB)
Shelby Star Jail Log
Unreasonable Zen Riddle Crossword
HP PARTSURFER - spare part search portal
Top Songs On Octane 2022
Rund um die SIM-Karte | ALDI TALK
MethStreams Live | BoxingStreams
Chattanooga Booking Report
Dreammarriage.com Login
Craigs List Jonesboro Ar
Craigslist Gigs Wichita Ks
Dollar Tree's 1,000 store closure tells the perils of poor acquisitions
Tripadvisor Vancouver Restaurants
Nina Flowers
Lamont Mortuary Globe Az
Expendables 4 Showtimes Near Malco Tupelo Commons Cinema Grill
Bekkenpijn: oorzaken en symptomen van pijn in het bekken
Sound Of Freedom Showtimes Near Amc Mountainside 10
Swoop Amazon S3
Oklahoma City Farm & Garden Craigslist
How To Get To Ultra Space Pixelmon
303-615-0055
17 of the best things to do in Bozeman, Montana
Publix Store 840
Bloons Tower Defense 1 Unblocked
Latest Posts
Article information

Author: Stevie Stamm

Last Updated:

Views: 5647

Rating: 5 / 5 (80 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Stevie Stamm

Birthday: 1996-06-22

Address: Apt. 419 4200 Sipes Estate, East Delmerview, WY 05617

Phone: +342332224300

Job: Future Advertising Analyst

Hobby: Leather crafting, Puzzles, Leather crafting, scrapbook, Urban exploration, Cabaret, Skateboarding

Introduction: My name is Stevie Stamm, I am a colorful, sparkling, splendid, vast, open, hilarious, tender person who loves writing and wants to share my knowledge and understanding with you.