Table of Contents

Struct XlsxCellValue

Namespace
DocWright.Formats.Xlsx
Assembly
DocWright.Formats.Xlsx.dll

One cell's value: the thing Excel stores, as opposed to the thing it displays.

public readonly struct XlsxCellValue : IEquatable<XlsxCellValue>
Implements
Inherited Members

Remarks

The distinction is the whole point of writing a spreadsheet rather than a table of strings. A cell holding Number(decimal) with a number format of #,##0 displays as 612,940 and still sums; the same cell holding the text "612,940" displays identically and sums to zero. The reference implementation makes the same split — measured on its own output, a report's =Sum(Fields!Total.Value) cell is <v>612940</v> with the thousands separator living in the style — so anything that arrives here already formatted has lost something that cannot be recovered downstream.

How numbers are serialized, and the one limit that implies. Every number is carried as decimal and written with InvariantCulture. A double passed to Number(double) is converted on the way in, which rounds it to 15 significant digits — the same precision Excel itself displays, and the same precision .NET Framework's own formatter works to.

That conversion is what makes the output identical on every target framework. Formatting a double directly does not: .NET Core 3.0 changed double.ToString to work from the exact binary value while .NET Framework works from fifteen digits, so the same cell would serialize differently on net48 and net10 and the determinism rule would be broken by a call that looks harmless. Measured across both runtimes, the conversion used here agrees on every value in range. A magnitude beyond decimal's range — roughly 7.9E28 — cannot be converted and is written in scientific notation from its 15 significant digits instead; the value survives, its exact binary tail does not, and Excel would not have shown that tail either.

Properties

Blank

Gets the empty value.

IsOutOfDecimalRange

Gets whether the value came from a double too large for decimal.

Kind

Gets what this value holds.

NumberValue

Gets the number, for the numeric, boolean and date kinds; otherwise zero.

OutOfRangeValue

Gets the original double when IsOutOfDecimalRange; otherwise zero.

TextValue

Gets the text, for Text and Error; otherwise empty.

Methods

Boolean(bool)

Creates a boolean value.

Date(DateTime)

Creates a date value, stored as the serial number Excel dates use.

Equals(XlsxCellValue)
Equals(object?)
Error(string?)

Creates an error literal.

GetHashCode()
Number(decimal)

Creates a numeric value.

Number(double)

Creates a numeric value from a double, rounded to 15 significant digits.

Text(string?)

Creates a text value.

Operators

operator ==(XlsxCellValue, XlsxCellValue)

Returns whether two values are equal.

operator !=(XlsxCellValue, XlsxCellValue)

Returns whether two values differ.