GSS.Spreadsheet (elixir_google_spreadsheets v0.4.0)

Model of Google Spreadsheet for external interaction.

Summary

Types

State of currently active Google spreadsheet

Functions

Add Conditional Formula using a boolean rule (as opposed to a gradient rule).

Append row in a spreadsheet after an index.

Batch update to append multiple rows.

Returns a specification to start this module under a supervisor.

Clear row in a spreadsheet by index.

Batched clear, which deletes more then one record. Pass either an array of ranges, or start and end row indexes.

Granular read by a custom range from a spreadsheet.

Freeze Row or Column Header.

Get sheet id associated with list_name in state.

Combine the sheet_id into the grid_range, and drop any values from the range that are nil.

Get spreadsheet internal id.

Get spreadsheet properties.

Read row in a spreadsheet by index.

Batched read, which returns more than one record. Pass either an array of ranges (or rows), or start and end row indexes.

Get total amount of rows in a spreadsheet.

Get spreadsheet sheets from properties.

Override row in a spreadsheet by index.

Batch update to write multiple rows.

Types

grid_range()

@type grid_range() :: %{
  row_from: integer(),
  row_to: integer(),
  col_from: integer(),
  col_to: integer()
}

spreadsheet_data()

@type spreadsheet_data() :: [String.t()]

spreadsheet_response()

@type spreadsheet_response() :: {:json, map()} | {:error, Exception.t()} | no_return()

state()

@type state() :: map()

State of currently active Google spreadsheet:

%{
    spreadsheet_id => "16Wgt0fuoYDgEAtGtYKF4jdjAhZez0q77UhkKdeKI6B4",
    list_name => nil,
    sheet_id => nil
}

Functions

add_conditional_format(pid, grid_range, params, opts \\ [])

@spec add_conditional_format(
  pid(),
  grid_range(),
  %{formula: String.t(), color_map: map()},
  Keyword.t()
) :: {:ok, list()} | {:error, Exception.t()}

Add Conditional Formula using a boolean rule (as opposed to a gradient rule).

Required keys in params:

  • formula: A value the condition is based on. The value is parsed as if the user typed into a cell. Formulas are supported (and must begin with an = or a '+').
  • color_map: Represents a color in the RGBA color space. Keys are red, green, blue, and alpha, and each value is in the interval [0, 1].

add_number_format(pid, grid_range, params, opts \\ [])

@spec add_number_format(
  pid(),
  grid_range(),
  %{type: String.t(), pattern: String.t()},
  Keyword.t()
) :: {:ok, list()} | {:error, Exception.t()}

Add Number Format.

Required keys in params:

  • type: The number format of the cell (e.g., DATE or TIME).
  • pattern: Pattern string used for formatting (e.g., yyyy-mm-dd).

append_row(pid, row_index, column_list, options \\ [])

@spec append_row(pid(), integer(), spreadsheet_data(), Keyword.t()) :: :ok

Append row in a spreadsheet after an index.

append_rows(pid, row_index, data, options \\ [])

@spec append_rows(pid(), integer(), [spreadsheet_data()], Keyword.t()) ::
  :ok | {:error, Exception.t()}

Batch update to append multiple rows.

batch_update_query(spreadsheet_id, request_body, options, state)

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear_basic_filter(pid, opts \\ [])

@spec clear_basic_filter(pid(), Keyword.t()) :: {:ok, map()} | {:error, Exception.t()}

Clear Basic Filter.

clear_row(pid, row_index, options \\ [])

@spec clear_row(pid(), integer(), Keyword.t()) :: :ok

Clear row in a spreadsheet by index.

clear_rows(pid, ranges)

@spec clear_rows(pid(), [String.t()]) :: :ok | {:error, Exception.t()}

Batched clear, which deletes more then one record. Pass either an array of ranges, or start and end row indexes.

clear_rows(pid, ranges, options)

@spec clear_rows(pid(), [String.t()], Keyword.t()) :: :ok | {:error, Exception.t()}
@spec clear_rows(pid(), integer(), integer()) :: :ok | {:error, Exception.t()}

clear_rows(pid, row_index_start, row_index_end, options)

@spec clear_rows(pid(), integer(), integer(), Keyword.t()) ::
  :ok | {:error, Exception.t()}

col_number_to_letters(col_number)

@spec col_number_to_letters(integer()) :: String.t()

fetch(pid, range)

@spec fetch(pid(), String.t()) :: {:ok, spreadsheet_data()} | {:error, Exception.t()}

Granular read by a custom range from a spreadsheet.

filter_specs(arg1)

freeze_header(pid, params, opts \\ [])

@spec freeze_header(pid(), %{dim: :row | :col, n_freeze: integer()}, Keyword.t()) ::
  {:ok, list()} | {:error, Exception.t()}

Freeze Row or Column Header.

Required keys in params:

  • dim: Either :row or :col to set the dimension to freeze.
  • n_freeze: Set the number of rows or columns to freeze.

get_sheet_id(pid)

@spec get_sheet_id(pid()) :: {:ok, integer()}

Get sheet id associated with list_name in state.

grid_range(sheet_id, map)

@spec grid_range(integer(), grid_range()) :: map()

Combine the sheet_id into the grid_range, and drop any values from the range that are nil.

id(pid)

@spec id(pid()) :: String.t()

Get spreadsheet internal id.

properties(pid)

@spec properties(pid()) :: map()

Get spreadsheet properties.

range(row_from, row_to, column_from, column_to)

@spec range(integer(), integer(), integer(), integer()) :: String.t()

range(row_from, row_to, column_from, column_to, state)

@spec range(integer(), integer(), integer(), integer(), state()) :: String.t()

read_row(pid, row_index, options \\ [])

@spec read_row(pid(), integer(), Keyword.t()) ::
  {:ok, spreadsheet_data()} | {:error, Exception.t()}

Read row in a spreadsheet by index.

read_rows(pid, ranges)

@spec read_rows(pid(), [String.t()] | [integer()]) ::
  {:ok, [spreadsheet_data() | nil]} | {:error, Exception.t()}

Batched read, which returns more than one record. Pass either an array of ranges (or rows), or start and end row indexes.

By default it returns nils for an empty rows, use pad_empty: true and column_to: integer options to fill records with an empty string values.

read_rows(pid, ranges, options)

@spec read_rows(pid(), [String.t()] | [integer()], Keyword.t()) ::
  {:ok, [spreadsheet_data()]} | {:error, Exception.t()}
@spec read_rows(pid(), integer(), integer()) ::
  {:ok, [spreadsheet_data()]} | {:error, atom()}

read_rows(pid, row_index_start, row_index_end, options)

@spec read_rows(pid(), integer(), integer(), Keyword.t()) ::
  {:ok, [spreadsheet_data()]} | {:error, atom()}

rows(pid, options \\ [])

@spec rows(pid(), Keyword.t()) :: {:ok, integer()} | {:error, Exception.t()}

Get total amount of rows in a spreadsheet.

set_basic_filter(pid, grid_range, params, opts \\ [])

@spec set_basic_filter(pid(), grid_range(), map(), Keyword.t()) ::
  {:ok, list()} | {:error, Exception.t()}

Set Basic Filter.

Two options for params:

  • To not filter out any rows, pass an empty map.
  • To filter out rows based on a column value, add these keys: col_idx, condition_type, user_entered_value.

set_font(pid, grid_range, params, opts \\ [])

@spec set_font(pid(), grid_range(), %{font_family: String.t()}, Keyword.t()) ::
  {:ok, list()} | {:error, Exception.t()}

Set Font.

Required key in params: font_family.

sheets(pid, options \\ [])

@spec sheets(pid(), Keyword.t()) :: [map()] | map()

Get spreadsheet sheets from properties.

start_link(spreadsheet_id, opts)

@spec start_link(String.t(), Keyword.t()) :: {:ok, pid()}

update_border(pid, grid_range, params, opts \\ [])

@spec update_border(pid(), grid_range(), map(), Keyword.t()) ::
  {:ok, list()} | {:error, Exception.t()}

Update Border.

Map params can only have keys in [:top, :bottom, :left, :right]. If a key is omitted, then the border remains as-is on that side. Subkeys: style, red, green, blue, alpha.

update_col_width(pid, params, opts \\ [])

@spec update_col_width(
  pid(),
  %{col_idx: integer(), col_width: integer()},
  Keyword.t()
) ::
  {:ok, list()} | {:error, Exception.t()}

Update Column Width.

Required keys in params:

  • col_idx: Index of column.
  • col_width: Column width in pixels.

update_col_wrap(pid, grid_range, params, opts \\ [])

@spec update_col_wrap(pid(), grid_range(), %{wrap_strategy: String.t()}, Keyword.t()) ::
  {:ok, list()} | {:error, Exception.t()}

Update Column Wrap.

Required keys in params:

  • wrap_strategy: How to wrap text in a cell. Options: [overflow_cell, clip, wrap].

update_sheet_size(pid, row_count, col_count, options \\ [])

@spec update_sheet_size(pid(), integer(), integer(), Keyword.t()) ::
  {:ok, list()} | {:error, Exception.t()}

write_row(pid, row_index, column_list, options \\ [])

@spec write_row(pid(), integer(), spreadsheet_data(), Keyword.t()) :: :ok

Override row in a spreadsheet by index.

write_rows(pid, ranges, data, opts \\ [])

@spec write_rows(pid(), [String.t()], [spreadsheet_data()], Keyword.t()) ::
  {:ok, list()} | {:error, Exception.t()}

Batch update to write multiple rows.

Range schema should define the same amount of rows as amound of records in data and same amount of columns as entries in data record.