ExVEx.OOXML.SharedStrings (ExVEx v0.1.1)

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 two maps: by_index and by_string. Both lookups and interns are O(1); interns are also allocation-cheap (map insertion, no copy of an N-element array as a tuple-backed table would need).

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

Returns the index of a string in the table, adding it if it isn't there yet. Returns {index, updated_sst}. O(1).

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

Types

t()

@type t() :: %ExVEx.OOXML.SharedStrings{
  by_index: %{required(non_neg_integer()) => String.t()},
  by_string: %{required(String.t()) => non_neg_integer()},
  count: non_neg_integer()
}

Functions

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, updated_sst}. O(1).

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.