Google Sheets — Read sheet
Google Sheets — Read sheet
Section titled “Google Sheets — Read sheet”Type: googlesheets-read-sheet · Package: Google Sheets Activities v1.0.5 · Output: DataTable
Reads all the data in a sheet and always returns it as a DataTable. It is the most common read: bring the whole content in to process it row by row, filter it or hand it to another activity.
How it works
Section titled “How it works”Reads the area with data of the given sheet (the first one if sheet is empty), from A1 to the last row and column with content, in a single call to Google.
- With
has-headers = true, the first row provides the column names and the following rows are the data. Cells in a row longer than the header row are dropped. - With
has-headers = false(default), columns are namedColumn1,Column2, … up to the longest row, and the first row is data too. - Every cell arrives as text as displayed in the sheet; empty cells as
"". A formula is read as its result.
Required parameters
Section titled “Required parameters”None.
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
session | ZoanGoogleSheetsSession | — | Session from Google Sheets — Open. Inside Open’s body it is inherited and you can leave it empty. |
sheet | string | — | Sheet name. If empty, reads the first sheet. |
has-headers | bool | false | Treat the first row as column names. If false, columns are named Column1, Column2, … |
Output
Section titled “Output”Always a DataTable with text columns. If the sheet is empty, returns an empty DataTable (no columns or rows), not an error: check it with rowCount(table) == 0. With has-headers = true and only the header row, returns the columns with no rows.
Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
No Google Sheets session available. Provide 'session' from a googlesheets-open activity, or place this activity inside the Open activity's body … | The activity is outside Open’s body and received no session. Move it inside the body or pass the saved session. |
The spreadsheet has no sheets to read. | sheet is empty and the document has no sheets visible to the API. |
A column named '…' already belongs to this DataTable. | With has-headers = true, two headers have the same text. Rename one in the sheet or read with has-headers = false. |
The service sheets has thrown an exception. HttpStatusCode is … | Google rejected the call: missing sheet or range, no access, expired token or quota exceeded. See Google API errors. |
Example
Section titled “Example”Google Sheets — Read sheet session = book sheet = "Orders" has-headers = true → output: ordersFor Each items = orders itemVariable = row └─ activities: Log message = str(row["Customer"]) + " — " + num(row["Total"])Related activities
Section titled “Related activities”- Read range — read only a range.
- Write sheet — write data back.
- Get sheet names — find out which sheets exist.