Reference documentation and code samples for the BigQuery API class Google::Cloud::Bigquery::External::SheetsSource.
SheetsSource
SheetsSource is a subclass of DataSource and
represents a Google Sheets external data source that can be queried
from directly, even though the data is not stored in BigQuery. Instead
of loading or streaming the data, this object references the external
data source.
require"google/cloud/bigquery"bigquery=Google::Cloud::Bigquery.newsheets_url="https://docs.google.com/spreadsheets/d/1234567980"sheets_table=bigquery.externalsheets_urldo|sheets|sheets.skip_leading_rows=1enddata=bigquery.query"SELECT * FROM my_ext_table",external:{my_ext_table:sheets_table}# Iterate over the first page of resultsdata.eachdo|row|putsrow[:name]end# Retrieve the next page of resultsdata=data.nextifdata.next?
Methods
#range
defrange()->String
Range of a sheet to query from. Only used when non-empty. Typical
format: {sheet_name}!{top_left_cell_id}:{bottom_right_cell_id}.
The number of rows at the top of a sheet that BigQuery will skip
when reading the data. The default value is 0.
This property is useful if you have header rows that should be
skipped. When autodetect is on, behavior is the following:
nil - Autodetect tries to detect headers in the first row. If
they are not detected, the row is read as data. Otherwise data is
read starting from the second row.
0 - Instructs autodetect that there are no headers and data
should be read starting from the first row.
N > 0 - Autodetect skips N-1 rows and tries to detect headers
in row N. If headers are not detected, row N is just skipped.
Otherwise row N is used to extract column names for the detected
schema.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["Version 1.44.2keyboard_arrow_down\n\n- [1.57.0 (latest)](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-External-SheetsSource)\n- [1.56.0](/ruby/docs/reference/google-cloud-bigquery/1.56.0/Google-Cloud-Bigquery-External-SheetsSource)\n- [1.55.0](/ruby/docs/reference/google-cloud-bigquery/1.55.0/Google-Cloud-Bigquery-External-SheetsSource)\n- [1.54.0](/ruby/docs/reference/google-cloud-bigquery/1.54.0/Google-Cloud-Bigquery-External-SheetsSource)\n- [1.53.0](/ruby/docs/reference/google-cloud-bigquery/1.53.0/Google-Cloud-Bigquery-External-SheetsSource)\n- [1.52.1](/ruby/docs/reference/google-cloud-bigquery/1.52.1/Google-Cloud-Bigquery-External-SheetsSource)\n- [1.51.1](/ruby/docs/reference/google-cloud-bigquery/1.51.1/Google-Cloud-Bigquery-External-SheetsSource)\n- [1.50.0](/ruby/docs/reference/google-cloud-bigquery/1.50.0/Google-Cloud-Bigquery-External-SheetsSource)\n- [1.49.1](/ruby/docs/reference/google-cloud-bigquery/1.49.1/Google-Cloud-Bigquery-External-SheetsSource)\n- [1.48.1](/ruby/docs/reference/google-cloud-bigquery/1.48.1/Google-Cloud-Bigquery-External-SheetsSource)\n- [1.47.0](/ruby/docs/reference/google-cloud-bigquery/1.47.0/Google-Cloud-Bigquery-External-SheetsSource)\n- [1.46.1](/ruby/docs/reference/google-cloud-bigquery/1.46.1/Google-Cloud-Bigquery-External-SheetsSource)\n- [1.45.0](/ruby/docs/reference/google-cloud-bigquery/1.45.0/Google-Cloud-Bigquery-External-SheetsSource)\n- [1.44.2](/ruby/docs/reference/google-cloud-bigquery/1.44.2/Google-Cloud-Bigquery-External-SheetsSource)\n- [1.43.1](/ruby/docs/reference/google-cloud-bigquery/1.43.1/Google-Cloud-Bigquery-External-SheetsSource)\n- [1.42.0](/ruby/docs/reference/google-cloud-bigquery/1.42.0/Google-Cloud-Bigquery-External-SheetsSource)\n- [1.41.0](/ruby/docs/reference/google-cloud-bigquery/1.41.0/Google-Cloud-Bigquery-External-SheetsSource)\n- [1.40.0](/ruby/docs/reference/google-cloud-bigquery/1.40.0/Google-Cloud-Bigquery-External-SheetsSource)\n- [1.39.0](/ruby/docs/reference/google-cloud-bigquery/1.39.0/Google-Cloud-Bigquery-External-SheetsSource)\n- [1.38.1](/ruby/docs/reference/google-cloud-bigquery/1.38.1/Google-Cloud-Bigquery-External-SheetsSource) \nReference documentation and code samples for the BigQuery API class Google::Cloud::Bigquery::External::SheetsSource.\n\nSheetsSource\n\n[SheetsSource](/ruby/docs/reference/google-cloud-bigquery/1.44.2/Google-Cloud-Bigquery-External-SheetsSource \"Google::Cloud::Bigquery::External::SheetsSource (class)\") is a subclass of [DataSource](/ruby/docs/reference/google-cloud-bigquery/1.44.2/Google-Cloud-Bigquery-External-DataSource \"Google::Cloud::Bigquery::External::DataSource (class)\") and\nrepresents a Google Sheets external data source that can be queried\nfrom directly, even though the data is not stored in BigQuery. Instead\nof loading or streaming the data, this object references the external\ndata source. \n\nInherits\n\n- [Google::Cloud::Bigquery::External::DataSource](./Google-Cloud-Bigquery-External-DataSource)\n\nExample \n\n```ruby\nrequire \"google/cloud/bigquery\"\n\nbigquery = Google::Cloud::Bigquery.new\n\nsheets_url = \"https://docs.google.com/spreadsheets/d/1234567980\"\nsheets_table = bigquery.external sheets_url do |sheets|\n sheets.skip_leading_rows = 1\nend\n\ndata = bigquery.query \"SELECT * FROM my_ext_table\",\n external: { my_ext_table: sheets_table }\n\n# Iterate over the first page of results\ndata.each do |row|\n puts row[:name]\nend\n# Retrieve the next page of results\ndata = data.next if data.next?\n```\n\nMethods\n\n#range \n\n def range() -\u003e String\n\nRange of a sheet to query from. Only used when non-empty. Typical\nformat: `{sheet_name}!{top_left_cell_id}:{bottom_right_cell_id}`. \n**Returns**\n\n- (String) --- Range of a sheet to query from.\n**Example** \n\n```ruby\nrequire \"google/cloud/bigquery\"\n\nbigquery = Google::Cloud::Bigquery.new\n\nsheets_url = \"https://docs.google.com/spreadsheets/d/1234567980\"\nsheets_table = bigquery.external sheets_url do |sheets|\n sheets.range = \"sheet1!A1:B20\"\nend\n\nsheets_table.range #=\u003e \"sheet1!A1:B20\"\n```\n\n#range= \n\n def range=(new_range)\n\nSet the range of a sheet to query from. Only used when non-empty.\nTypical format:\n`{sheet_name}!{top_left_cell_id}:{bottom_right_cell_id}`. \n**Parameter**\n\n- **new_range** (String) --- New range of a sheet to query from.\n**Example** \n\n```ruby\nrequire \"google/cloud/bigquery\"\n\nbigquery = Google::Cloud::Bigquery.new\n\nsheets_url = \"https://docs.google.com/spreadsheets/d/1234567980\"\nsheets_table = bigquery.external sheets_url do |sheets|\n sheets.range = \"sheet1!A1:B20\"\nend\n\nsheets_table.range #=\u003e \"sheet1!A1:B20\"\n```\n\n#skip_leading_rows \n\n def skip_leading_rows() -\u003e Integer\n\nThe number of rows at the top of a sheet that BigQuery will skip\nwhen reading the data. The default value is `0`.\n\nThis property is useful if you have header rows that should be\nskipped. When `autodetect` is on, behavior is the following:\n\n- `nil` - Autodetect tries to detect headers in the first row. If they are not detected, the row is read as data. Otherwise data is read starting from the second row.\n- `0` - Instructs autodetect that there are no headers and data should be read starting from the first row.\n- `N \u003e 0` - Autodetect skips `N-1` rows and tries to detect headers in row `N`. If headers are not detected, row `N` is just skipped. Otherwise row `N` is used to extract column names for the detected schema. \n**Returns**\n\n- (Integer)\n**Example** \n\n```ruby\nrequire \"google/cloud/bigquery\"\n\nbigquery = Google::Cloud::Bigquery.new\n\nsheets_url = \"https://docs.google.com/spreadsheets/d/1234567980\"\nsheets_table = bigquery.external sheets_url do |sheets|\n sheets.skip_leading_rows = 1\nend\n\nsheets_table.skip_leading_rows #=\u003e 1\n```\n\n#skip_leading_rows= \n\n def skip_leading_rows=(row_count)\n\nSet the number of rows at the top of a sheet that BigQuery will skip\nwhen reading the data. \n**Parameter**\n\n- **row_count** (Integer) --- New skip_leading_rows value\n**Example** \n\n```ruby\nrequire \"google/cloud/bigquery\"\n\nbigquery = Google::Cloud::Bigquery.new\n\nsheets_url = \"https://docs.google.com/spreadsheets/d/1234567980\"\nsheets_table = bigquery.external sheets_url do |sheets|\n sheets.skip_leading_rows = 1\nend\n\nsheets_table.skip_leading_rows #=\u003e 1\n```"]]