CellValue
public readonly struct CellValue
Namespace SharpCell · package SharpCell
A value produced by a cell or a formula. default is CellValue.Empty. Equality is identity (same kind, same payload, ordinal text), not Excel's =.
Properties
Empty
public static CellValue Empty { get; }
An empty cell.
False
public static CellValue False { get; }
The logical value FALSE.
IsError
public bool IsError { get; }
Whether the value is an Excel error.
Kind
public CellValueKind Kind { get; }
The kind of value; check it before calling one of the As methods.
Missing
public static CellValue Missing { get; }
An omitted function argument, as in IF(A1,,B1).
True
public static CellValue True { get; }
The logical value TRUE.
Methods
Array(CellValue[,])
public static CellValue Array(CellValue[,] values)
A rectangular array. The array is taken by reference and must not be mutated afterwards. Excel has no empty arrays, so both dimensions must be at least 1.
AsArray()
public CellValue[,] AsArray()
The array, rows first. Throws InvalidOperationException when CellValue.Kind is not CellValueKind.Array.
AsBoolean()
public bool AsBoolean()
The logical value. Throws InvalidOperationException when CellValue.Kind is not CellValueKind.Boolean.
AsDateTime(DateSystem)
public DateTime AsDateTime(DateSystem system)
The number read as a date and time: Excel stores dates as serial days counted from the workbook's system (Workbook.DateSystem), the time of day as the fraction, here rounded to the millisecond. The result's kind is DateTimeKind.Unspecified, as Excel knows no time zones.
Exceptions
InvalidOperationException: CellValue.Kind is not CellValueKind.Number.ArgumentOutOfRangeException: The number is no date: negative, past 9999-12-31, or 60 in the 1900 system, which Excel shows as the non-existent 1900-02-29.
AsError()
public ErrorKind AsError()
The error. Throws InvalidOperationException when CellValue.Kind is not CellValueKind.Error.
AsLambda()
public LambdaValue AsLambda()
The function value. Throws InvalidOperationException when CellValue.Kind is not CellValueKind.Lambda.
AsNumber()
public double AsNumber()
The number. Throws InvalidOperationException when CellValue.Kind is not CellValueKind.Number.
AsText()
public string AsText()
The text. Throws InvalidOperationException when CellValue.Kind is not CellValueKind.Text.
Boolean(bool)
public static CellValue Boolean(bool value)
A logical value.
DateTime(DateTime, DateSystem)
public static CellValue DateTime(DateTime value, DateSystem system)
A date and time as the serial number Excel stores: days counted from the workbook's system (Workbook.DateSystem), the time of day as the fraction.
Exceptions
ArgumentOutOfRangeException: The date is before the date system starts: 1899-12-31 in the 1900 system, 1904-01-01 in the 1904 system.
Equals(CellValue)
public bool Equals(CellValue other)
Whether both values have the same kind and content; arrays are compared element by element. This is not Excel's =, which ignores case.
Equals(object)
public override bool Equals(object? obj)
Whether obj is a CellValue equal to this one.
Error(ErrorKind)
public static CellValue Error(ErrorKind kind)
An error value.
GetHashCode()
public override int GetHashCode()
A hash code consistent with CellValue.Equals.
Lambda(LambdaValue)
public static CellValue Lambda(LambdaValue value)
A function value.
Number(double)
public static CellValue Number(double value)
A number. Excel has neither NaN, infinities nor negative zero: non-finite input becomes #NUM! and -0 becomes 0.
Text(string)
public static CellValue Text(string value)
A text value.
ToString()
public override string ToString()
Formats the value the way it would be written as a formula literal.
Operators
implicit operator CellValue(bool)
public static implicit operator CellValue(bool value)
A logical value, so cell.Value = true works.
implicit operator CellValue(double)
public static implicit operator CellValue(double value)
A number, so cell.Value = 42 works.
implicit operator CellValue(string)
public static implicit operator CellValue(string value)
A text value, so cell.Value = "text" works.
operator !=(CellValue, CellValue)
public static bool operator !=(CellValue left, CellValue right)
Whether the values differ, as CellValue.Equals.
operator ==(CellValue, CellValue)
public static bool operator ==(CellValue left, CellValue right)
Whether the values are equal, as CellValue.Equals.