pub enum CellValue {
Empty,
Text(String),
Number(f64),
Formula {
formula: Option<String>,
cached_value: Option<f64>,
},
Boolean(bool),
Date(ExcelDateTime),
RichText(Vec<RichTextRun>),
ArrayFormula {
formula: String,
range: String,
cached_value: Option<f64>,
},
SharedFormula {
formula: Option<String>,
group_index: u32,
range: Option<String>,
cached_value: Option<f64>,
},
}Expand description
A cell’s value.
Variants§
Empty
No value — an empty cell. This crate never writes a <c> element for one (matching real
Excel output, which omits genuinely empty cells entirely) unless the cell carries a
CellFormat, in which case a self-closing <c r=".." s=".."/> is written (a
styled-but-empty cell — real Excel does this too, e.g. for a pre-formatted but not yet
filled-in cell). This variant also exists so a sparse row read back from a real .xlsx can
still be represented densely, keeping a cell’s Vec position equal to its real column. The
default value for a freshly-constructed Cell.
Text(String)
A text value (<c t="s"><v>N</v></c>, an index into the shared strings table
xl/sharedStrings.xml — CT_Cell’s t="str" in-cell-formula-result and t="inlineStr"
variants are not modeled, matching Excel’s own default behavior of always deduplicating
repeated text through the shared strings table rather than writing it inline).
Number(f64)
A numeric value (<c><v>..</v></c>, CT_Cell’s default/"n" type — a plain f64, written
with Rust’s own default floating-point-to-string formatting; not a CT_Cell’s t="b"
(boolean) or t="e" (error) variant).
Formula
A formula cell (<c><f>..</f><v>..</v></c>, CT_CellFormula + cached CT_Cell/@v).
Formula evaluation is out of scope — only the literal formula text and, if present, its
last-computed cached value are stored, never recomputed.
A cell built via Cell::formula always has Some formula text; writing a cell with
formula: None falls back to writing just the cached value with no <f> element at all
(see writer.rs::write_cell). A real .xlsx’s t="shared" formula cells (both the group’s
master and its followers) now read back as SharedFormula
instead of this variant — point 52, which replaced this variant’s earlier “drop the
si/ref, keep only the cached value” limit with a dedicated, round-trippable
representation.
Fields
Boolean(bool)
A boolean value (<c t="b"><v>0|1</v></c>). Fully round-trippable (unlike Date, see
below).
Date(ExcelDateTime)
A date/time value. Write side only: Cell::date converts an ExcelDateTime to the
serial-day number Excel actually stores (<c><v>..</v></c>, a plain numeric cell,
CT_Cell’s default type — SpreadsheetML has no dedicated date cell type, a date is always
just a number that happens to carry a date-shaped numFmtId), so writing one produces
exactly the same XML shape as CellValue::Number. Reading a workbook back never
reconstructs this variant, even for a cell this crate’s own writer produced — a
date-formatted cell reads back as CellValue::Number(serial), the caller’s own
responsibility to reinterpret using the cell’s CellFormat::number_format, same honest
“storage, not clever inference” posture as this crate’s formula-evaluation scope limit. Pair
Cell::date with a CellFormat::with_number_format (e.g. "dd/mm/yyyy") for Excel to
actually display it as a date rather than a raw serial number — this crate does not do that
automatically (see Cell::date’s doc comment), matching word-ooxml’s
PageSetup.orientation “caller’s responsibility” precedent.
RichText(Vec<RichTextRun>)
A text value with per-run character formatting (<si><r>..</r></si> in
xl/sharedStrings.xml — the “rich text” shared string form, as opposed to
CellValue::Text’s plain <si><t>..</t></si> form). Fully round-trippable.
ArrayFormula
An array (CSE, “Ctrl+Shift+Enter”) formula (<c><f t="array" ref=".">.</f><v>.</v></c>,
CT_CellFormula’s t="array" variant) — distinct from Formula’s plain/shared forms. Real
Excel writes the literal <f t="array" ref="."> only on the array range’s top-left (anchor)
cell — every other cell the range covers gets no <f> at all, just its own cached <v>
(this crate’s own writer only ever builds a Cell holding this variant for the anchor cell
itself; the caller is responsible for the other cells in range carrying plain
CellValue::Number/Empty cells with the right cached values, same “caller keeps things in
sync” posture as ExcelTable::columns needing to match the header row’s actual text).
Reading a real .xlsx’s array-formula continuation cells (which carry no <f> at all)
simply reads them back as whatever plain value type their own <v>/t attribute says —
this crate does not reconstruct that they were once part of an array’s range.
Fields
One cell of a shared-formula group (<c><f t="shared" si=".." ref="..">..</f><v>..</v></c>
on the group’s master cell, or <c><f t="shared" si=".."/><v>..</v></c> on a follower cell
— CT_CellFormula’s t="shared" variant). Confirmed against sml.xsd: si (the group’s
shared index) is the only attribute present on every cell in the group; ref (the group’s
full range) is only meaningful — and, matching real Excel’s own convention, only ever
written — on the master cell, the one carrying the actual formula text. This crate does
not compute or shift relative references for follower cells (e.g. deriving "A3*B3"
from a master’s "A2*B2") — same “storage, not evaluation” posture as
Formula itself; the caller supplies each follower’s own
already-correct formula text (or None, matching what real Excel itself writes for a
follower — see Cell::shared_formula_follower).