Skip to content

Google Sheets Activities

Version: 1.0.5  ·  ID: zoan-packages-googlesheets  ·  Author: Zoan Software

The Google Sheets package reads and writes Google spreadsheets directly in the cloud (through its API). It is the Excel counterpart for Google documents: ideal when the data lives in a shared sheet that several people or systems update, with no files to download and upload again.

Unlike Excel (which opens a local file), Google Sheets reaches a sheet in the cloud, so it needs authorization. Google Sheets — Open supports two modes, chosen with authType:

ModeWhat you needWhen it fits
oauth (default)A Google OAuth connection created and authorized in Zoan Cloud with the Sheets permission. Pass it in credential as credential("code-name"). Zoan Cloud refreshes the token for you.The robot acts on a person’s account or a team mailbox.
service-accountA service account key (the full JSON) stored as a credential, in serviceAccount. The sheet must be shared with the service account’s email. Optional: impersonateUser to act on behalf of a Workspace user (domain-wide delegation).Unattended runs with no person’s consent.

In both modes the activities use the read and write spreadsheets permission (https://www.googleapis.com/auth/spreadsheets).

What you needWhere to get it
Spreadsheet ID (spreadsheetId)It is in the sheet URL: docs.google.com/spreadsheets/d/{ID}/edit — copy the {ID} part.

Every operation works on a session (ZoanGoogleSheetsSession) that you open with Google Sheets — Open and share with the other activities:

  • With body: the activities inside inherit the session without setting session; when the block ends the session closes by itself, even if something fails.
  • Without body: save the session in a variable, pass it in session and close it with Google Sheets — Close.
Google Sheets — Open credential = credential("google-operations") spreadsheetId = sheetId
└─ body:
Google Sheets — Read sheet sheet = "Orders" has-headers = true → output: orders
... process ...
  • Cells and ranges use A1 notation: A1, B3, A1:E10, A:E (whole columns), 1:100 (whole rows).
  • Sheets are referenced by name ("Orders"). If you leave it empty, the first sheet of the document is used. Type the name as is, without quotes: the activity wraps it in single quotes and doubles any apostrophe, so names like Sales O'Brien, Sheet with spaces or A1 work. Since version 1.0.5.
  • What you read is text: reads return the value as displayed in the sheet (with its number and date format), always as a string. Convert with num() or the date functions before calculating. A formula is read as its result.
  • has-headers: in Read sheet and Read range, true makes the first row the column names of the DataTable; false (default) names the columns Column1, Column2, … The result is always a DataTable.
ActivityTypeOutputWhat it does
Google Sheets — Opengooglesheets-openZoanGoogleSheetsSessionOpens an authenticated session with a spreadsheet
Google Sheets — Closegooglesheets-close—Closes the session
ActivityTypeOutputWhat it does
Read sheetgooglesheets-read-sheetDataTableReads a whole sheet
Read rangegooglesheets-read-rangeDataTableReads a range
Read cellgooglesheets-read-cellobjectReads one cell
Used rangegooglesheets-get-used-rangeDictionary<string,object>Size of the area with data
Get sheet namesgooglesheets-get-sheet-namesList<string>Names of the sheets
Find cellgooglesheets-find-cellDictionary<string,object>Finds a cell by value
Find rowgooglesheets-find-rowDictionary<string,object>Finds a row by a column value
ActivityTypeOutputWhat it does
Write sheetgooglesheets-write-sheet—Writes data from A1
Write rangegooglesheets-write-range—Writes from a given cell
Write cellgooglesheets-write-cell—Writes one cell
Append rowsgooglesheets-append—Appends rows at the end
Clear rangegooglesheets-clear-range—Clears the content of a range

When Google rejects a call, the activity fails with a GoogleApiException whose message starts with The service sheets has thrown an exception. HttpStatusCode is … followed by Google’s text. The status code tells you the cause:

CodeUsual causeWhat to do
NotFoundThe spreadsheetId does not exist or was copied wrong.Copy the ID from the sheet URL.
BadRequest (Unable to parse range: …)The sheet or range does not exist (misspelled sheet name, invalid range).Check the names with Get sheet names.
ForbiddenThe account has no access to the sheet, or the connection lacks the Sheets permission.Share the sheet with the account (or the service account’s email) or re-authorize the connection with the permission.
UnauthorizedThe token is no longer valid (access revoked, connection expired).Reconnect the connection in Zoan Cloud.
TooManyRequestsGoogle’s per-minute request quota was exceeded.Group reads and writes (one DataTable instead of many cells) and wrap the activity in Retry with a delay.

Catch any of them with Try / Catch; error.Type is GoogleApiException.