A cell: where it is, what it holds, how it looks.
iex> Sheetshow.Cell.new("Costs!B4", 0.22, %{number_format: "0%"})
%Sheetshow.Cell{
coord: %Sheetshow.Coord{row: 3, col: 1, sheet: "Costs"},
value: 0.22,
style: %{number_format: "0%"},
meta: %{}
}A spreadsheet is a list of these, in no particular order. Knowing cells, you know most of Sheetshow: everything else builds lists of them, moves them about, or turns them into requests.
meta is yours. No writer looks at it; readers put what they learned there,
such as the text Sheets displayed for a value. Values and styles are checked
by validate/1, which writers call, rather than on construction.
Summary
Functions
Builds a cell at a Sheetshow.Coord or an A1 reference (raising if the
reference is malformed).
Puts the cell on a sheet.
Merges a style into the cell's, the new keys winning.
Moves the cell by rows down and cols right; see Sheetshow.Coord.shift/3.
Whether the term is a valid cell.
Checks the coordinate, value and style.
Types
@type t() :: %Sheetshow.Cell{ coord: Sheetshow.Coord.t(), meta: map(), style: Sheetshow.Style.t(), value: Sheetshow.Value.t() }
Functions
@spec new(Sheetshow.Coord.t() | String.t(), Sheetshow.Value.t(), Sheetshow.Style.t()) :: t()
Builds a cell at a Sheetshow.Coord or an A1 reference (raising if the
reference is malformed).
iex> Sheetshow.Cell.new(Sheetshow.Coord.new(0, 0), "Item")
%Sheetshow.Cell{coord: %Sheetshow.Coord{row: 0, col: 0, sheet: nil}, value: "Item", style: %{}, meta: %{}}
Puts the cell on a sheet.
iex> Sheetshow.Cell.new("A1") |> Sheetshow.Cell.put_sheet("Costs") |> Map.fetch!(:coord) |> Sheetshow.Coord.to_a1()
"Costs!A1"
@spec put_style(t(), Sheetshow.Style.t()) :: t()
Merges a style into the cell's, the new keys winning.
iex> Sheetshow.Cell.new("A1", 1, %{bold: true})
...> |> Sheetshow.Cell.put_style(%{bold: false, italic: true})
...> |> Map.fetch!(:style)
%{bold: false, italic: true}
Moves the cell by rows down and cols right; see Sheetshow.Coord.shift/3.
iex> Sheetshow.Cell.new("A1") |> Sheetshow.Cell.shift(1, 2) |> Map.fetch!(:coord) |> Sheetshow.Coord.to_a1()
"C2"
Whether the term is a valid cell.
@spec validate(term()) :: :ok | {:error, Sheetshow.Error.t()}
Checks the coordinate, value and style.
iex> Sheetshow.Cell.validate(Sheetshow.Cell.new("A1", 1, %{bold: true}))
:ok
iex> {:error, %Sheetshow.Error{reason: :invalid_style}} =
...> Sheetshow.Cell.validate(Sheetshow.Cell.new("A1", 1, %{bold: "yes"}))