ExVEx.OOXML.Styles (ExVEx v0.1.3)

Copy Markdown View Source

Parser for xl/styles.xml.

The OOXML style model is an indirection graph: a cell carries a style index s="N" into cellXfs; each <xf> there points at a numFmt, font, fill, and border by further indices.

ExVEx parses the indirection arrays (numFmts, fonts, fills, borders, cellXfs) and exposes resolve/2 to flatten an <xf> index into a user-facing %ExVEx.Style{} record.

Built-in number format IDs (0..163) are not listed in numFmts at all; workbook-specific custom formats start at ID 164.

Summary

Functions

Decides whether a cell format represents a date (or date-time / time).

The format code string for a given numFmt id, resolving built-ins.

Dereferences a cell's style index into a flat %ExVEx.Style{} record. Returns a default style for nil (an unstyled cell).

Re-serialises the stylesheet into its original XML container, rewriting only the <cellXfs> section. All other elements (fonts, fills, borders, cellStyles, dxfs, tableStyles, etc.) are preserved at the element level from original_xml.

Adds (or finds) an <xf> with the given numFmtId sitting on top of the default font / fill / border. Returns {index, updated_styles} — the index is the value that goes into a cell's s attribute.

Types

t()

@type t() :: %ExVEx.OOXML.Styles{
  borders: [ExVEx.Style.Border.t()],
  cell_formats: [ExVEx.OOXML.Styles.CellFormat.t()],
  fills: [ExVEx.Style.Fill.t()],
  fonts: [ExVEx.Style.Font.t()],
  num_fmts: [ExVEx.OOXML.Styles.NumFmt.t()]
}

Functions

cell_format(styles, index)

@spec cell_format(t(), non_neg_integer()) ::
  {:ok, ExVEx.OOXML.Styles.CellFormat.t()} | :error

date_format?(styles, cell_format)

@spec date_format?(t(), ExVEx.OOXML.Styles.CellFormat.t()) :: boolean()

Decides whether a cell format represents a date (or date-time / time).

format_code(styles, id)

@spec format_code(t(), non_neg_integer()) :: String.t()

The format code string for a given numFmt id, resolving built-ins.

parse(xml)

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

resolve(styles, index)

@spec resolve(t(), non_neg_integer() | nil) :: ExVEx.Style.t()

Dereferences a cell's style index into a flat %ExVEx.Style{} record. Returns a default style for nil (an unstyled cell).

serialize_into(styles, original_xml)

@spec serialize_into(t(), binary()) :: binary()

Re-serialises the stylesheet into its original XML container, rewriting only the <cellXfs> section. All other elements (fonts, fills, borders, cellStyles, dxfs, tableStyles, etc.) are preserved at the element level from original_xml.

upsert_date_format(styles, num_fmt_id)

@spec upsert_date_format(t(), non_neg_integer()) :: {non_neg_integer(), t()}

Adds (or finds) an <xf> with the given numFmtId sitting on top of the default font / fill / border. Returns {index, updated_styles} — the index is the value that goes into a cell's s attribute.