<!-- Generated by tools/SharpCell.Docs from the XML documentation comments. Do not edit; run the tool with 'generate'. -->

# CellValue

```csharp
public readonly struct CellValue
```

Namespace `SharpCell` · package `SharpCell`

A value produced by a cell or a formula. `default` is [CellValue.Empty](SharpCell.CellValue.md#empty). Equality is identity (same kind, same payload, ordinal text), not Excel's `=`.

## Properties

<a id="empty"></a>
### Empty

```csharp
public static CellValue Empty { get; }
```

An empty cell.

<a id="false"></a>
### False

```csharp
public static CellValue False { get; }
```

The logical value FALSE.

<a id="iserror"></a>
### IsError

```csharp
public bool IsError { get; }
```

Whether the value is an Excel error.

<a id="kind"></a>
### Kind

```csharp
public CellValueKind Kind { get; }
```

The kind of value; check it before calling one of the `As` methods.

<a id="missing"></a>
### Missing

```csharp
public static CellValue Missing { get; }
```

An omitted function argument, as in `IF(A1,,B1)`.

<a id="true"></a>
### True

```csharp
public static CellValue True { get; }
```

The logical value TRUE.

## Methods

<a id="array-cellvalue"></a>
### Array(CellValue[,])

```csharp
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.

<a id="asarray"></a>
### AsArray()

```csharp
public CellValue[,] AsArray()
```

The array, rows first. Throws `InvalidOperationException` when [CellValue.Kind](SharpCell.CellValue.md#kind) is not [CellValueKind.Array](SharpCell.CellValueKind.md#array).

<a id="asboolean"></a>
### AsBoolean()

```csharp
public bool AsBoolean()
```

The logical value. Throws `InvalidOperationException` when [CellValue.Kind](SharpCell.CellValue.md#kind) is not [CellValueKind.Boolean](SharpCell.CellValueKind.md#boolean).

<a id="asdatetime-datesystem"></a>
### AsDateTime(DateSystem)

```csharp
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](SharpCell.Workbook.md#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](SharpCell.CellValue.md#kind) is not [CellValueKind.Number](SharpCell.CellValueKind.md#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.

<a id="aserror"></a>
### AsError()

```csharp
public ErrorKind AsError()
```

The error. Throws `InvalidOperationException` when [CellValue.Kind](SharpCell.CellValue.md#kind) is not [CellValueKind.Error](SharpCell.CellValueKind.md#error).

<a id="aslambda"></a>
### AsLambda()

```csharp
public LambdaValue AsLambda()
```

The function value. Throws `InvalidOperationException` when [CellValue.Kind](SharpCell.CellValue.md#kind) is not [CellValueKind.Lambda](SharpCell.CellValueKind.md#lambda).

<a id="asnumber"></a>
### AsNumber()

```csharp
public double AsNumber()
```

The number. Throws `InvalidOperationException` when [CellValue.Kind](SharpCell.CellValue.md#kind) is not [CellValueKind.Number](SharpCell.CellValueKind.md#number).

<a id="astext"></a>
### AsText()

```csharp
public string AsText()
```

The text. Throws `InvalidOperationException` when [CellValue.Kind](SharpCell.CellValue.md#kind) is not [CellValueKind.Text](SharpCell.CellValueKind.md#text).

<a id="boolean-bool"></a>
### Boolean(bool)

```csharp
public static CellValue Boolean(bool value)
```

A logical value.

<a id="datetime-datetime-datesystem"></a>
### DateTime(DateTime, DateSystem)

```csharp
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](SharpCell.Workbook.md#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.

<a id="equals-cellvalue"></a>
### Equals(CellValue)

```csharp
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.

<a id="equals-object"></a>
### Equals(object)

```csharp
public override bool Equals(object? obj)
```

Whether `obj` is a [CellValue](SharpCell.CellValue.md) equal to this one.

<a id="error-errorkind"></a>
### Error(ErrorKind)

```csharp
public static CellValue Error(ErrorKind kind)
```

An error value.

<a id="gethashcode"></a>
### GetHashCode()

```csharp
public override int GetHashCode()
```

A hash code consistent with [CellValue.Equals](SharpCell.CellValue.md#equals-cellvalue).

<a id="lambda-lambdavalue"></a>
### Lambda(LambdaValue)

```csharp
public static CellValue Lambda(LambdaValue value)
```

A function value.

<a id="number-double"></a>
### Number(double)

```csharp
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`.

<a id="text-string"></a>
### Text(string)

```csharp
public static CellValue Text(string value)
```

A text value.

<a id="tostring"></a>
### ToString()

```csharp
public override string ToString()
```

Formats the value the way it would be written as a formula literal.

## Operators

<a id="op-implicit-bool"></a>
### implicit operator CellValue(bool)

```csharp
public static implicit operator CellValue(bool value)
```

A logical value, so `cell.Value = true` works.

<a id="op-implicit-double"></a>
### implicit operator CellValue(double)

```csharp
public static implicit operator CellValue(double value)
```

A number, so `cell.Value = 42` works.

<a id="op-implicit-string"></a>
### implicit operator CellValue(string)

```csharp
public static implicit operator CellValue(string value)
```

A text value, so `cell.Value = "text"` works.

<a id="op-inequality-cellvalue-cellvalue"></a>
### operator !=(CellValue, CellValue)

```csharp
public static bool operator !=(CellValue left, CellValue right)
```

Whether the values differ, as [CellValue.Equals](SharpCell.CellValue.md#equals-cellvalue).

<a id="op-equality-cellvalue-cellvalue"></a>
### operator ==(CellValue, CellValue)

```csharp
public static bool operator ==(CellValue left, CellValue right)
```

Whether the values are equal, as [CellValue.Equals](SharpCell.CellValue.md#equals-cellvalue).
