View Source Sheetex (Sheetex v0.5.0)

For when you just want to fetch some rows from a Google Sheet.

See fetch_rows/2 for more information.

Summary

Functions

Fetch rows from a Google Sheet.

Similar to fetch_rows/2, but raises an exception on failure.

Convert the result of fetch_rows/2 to a list of maps.

Types

@type cell() ::
  String.t()
  | integer()
  | float()
  | boolean()
  | nil
  | %{message: String.t() | nil, type: String.t() | nil}
@type option() ::
  {:range, String.t()} | {:key, String.t()} | {:oauth_token, String.t()}
@type rows() :: [[cell()]]

Functions

Link to this function

fetch_rows(spreadsheet_id, opts)

View Source
@spec fetch_rows(String.t(), [option()]) :: {:ok, rows()} | {:error, String.t()}

Fetch rows from a Google Sheet.

This function requires a Google Workspace API key or an OAuth token, which will be passed to the Google Sheets API. See Google’s official authorization docs.

Options

You must provide either key OR oauth_token for authorization.

  • key – API key.
  • oauth_token – OAuth token.
  • range – Use this option if you want to fetch a specific range from a spreadsheet using the A1 notation.

Output

  • The output will include a list of rows up to the last non-empty row in the sheet (or from within the specified range).
  • For each row, the output will contain a list of cell values up to the last non-empty cell.

Converting rows to key-value pairs

See to_kv/1 for converting the output into a list of maps.

Link to this function

fetch_rows!(spreadsheet_id, opts)

View Source
@spec fetch_rows!(String.t(), [option()]) :: rows()

Similar to fetch_rows/2, but raises an exception on failure.

@spec to_kv(rows(), atom_keys: boolean(), headers: list()) :: [map()]

Convert the result of fetch_rows/2 to a list of maps.

Values from the first row will be used as keys, unless the headers option containing a list of headers is provided. If a column contains an empty header, all values in that column will be dropped.