Skip to main content

CellValue

Enum CellValue 

Source
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.xmlCT_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

§formula: Option<String>

The formula text, without a leading = (e.g. "A2*B2").

§cached_value: Option<f64>

The formula’s last-computed value, if known.

§

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

§formula: String

The formula text, without a leading =.

§range: String

The array’s full range this formula fills (e.g. "B2:B10") — a single-cell array formula still needs its own cell as the range (e.g. "B2:B2").

§cached_value: Option<f64>

The formula’s last-computed value for this (the anchor) cell, if known.

§

SharedFormula

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).

Fields

§formula: Option<String>

The formula text, without a leading =Some on the group’s master cell, None on a follower (real Excel writes a follower’s <f> with no text content at all, just t/si).

§group_index: u32

This formula group’s shared index (si) — identical across every cell (master and every follower) belonging to the same group; a workbook may have several independent groups, each with its own index starting from 0.

§range: Option<String>

The group’s full range (ref) — Some only on the master cell (the one written first, real Excel omits it on every follower).

§cached_value: Option<f64>

This cell’s own last-computed value, if known.

Trait Implementations§

Source§

impl Clone for CellValue

Source§

fn clone(&self) -> CellValue

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CellValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for CellValue

Source§

fn default() -> CellValue

Returns the “default value” for a type. Read more
Source§

impl PartialEq for CellValue

Source§

fn eq(&self, other: &CellValue) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CellValue

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.