ExVEx.OOXML.SharedStrings (ExVEx v0.2.0)

Copy Markdown View Source

The shared string table (xl/sharedStrings.xml).

Most cell text in a real workbook is stored by index into this table — a cell with t="s" has a <v>N</v> that points at the Nth <si> entry.

Storage is ETS-backed: one :set table for index→string, another for string→index. Lookups are O(1). Interns are O(1) and allocate nothing beyond the single ETS row.

Because the tables are ETS, multiple %ExVEx.Workbook{} references derived from the same ExVEx.open/1 or ExVEx.new/0 share the same underlying SST state. This matches the sharing semantics of the per-sheet cell tables so that string-valued cell mutations remain internally consistent across workbook references.

Rich-text formatting (<r> runs, <rPr> properties) is flattened into plain text at parse time. Phonetic annotations (<phoneticPr>, <rPh>) are stripped from the parsed view. The original XML bytes remain in the workbook's parts map so untouched rich content round-trips even when ExVEx doesn't model it.

Summary

Functions

Releases the backing ETS tables. Call from ExVEx.close/1 when done.

Returns the index of a string in the table, adding it if it isn't there yet. Returns {index, sst}sst is the same struct (ETS mutation is in-place), included so callers can treat this identically to the Map-backed version.

Serialises the table back to an xl/sharedStrings.xml document.

Types

t()

@type t() :: %ExVEx.OOXML.SharedStrings{
  by_index_table: :ets.tid() | nil,
  by_string_table: :ets.tid() | nil
}

Functions

close(shared_strings)

@spec close(t()) :: :ok

Releases the backing ETS tables. Call from ExVEx.close/1 when done.

count(shared_strings)

@spec count(t()) :: non_neg_integer()

get(shared_strings, index)

@spec get(t(), integer()) :: {:ok, String.t()} | :error

intern(sst, text)

@spec intern(t(), String.t()) :: {non_neg_integer(), t()}

Returns the index of a string in the table, adding it if it isn't there yet. Returns {index, sst}sst is the same struct (ETS mutation is in-place), included so callers can treat this identically to the Map-backed version.

parse(xml)

@spec parse(binary()) :: {:ok, t()} | {:error, term()}

serialize(shared_strings)

@spec serialize(t()) :: binary()

Serialises the table back to an xl/sharedStrings.xml document.