Table of Contents

Struct XLCellValue

Namespace
SlapKit.Excel.Excel
Assembly
SlapKit.Excel.dll

A value of a single cell. It contains a value a specific Type. Structure provides following group of methods:

  • Is* properties to check type (IsNumber, IsBlank...)
  • Get* methods that return the stored value or throw InvalidCastException for incorrect type.
  • Explicit operators to convert XLCellValue to a concrete type. It is an equivalent of Get* methods.
  • TryConvert methods to try to get value of a specific type, even if the value is of a different type.
public readonly struct XLCellValue : IEquatable<XLCellValue>, IEquatable<Blank>, IEquatable<bool>, IEquatable<double>, IEquatable<string>, IEquatable<XLError>, IEquatable<DateTime>, IEquatable<TimeSpan>, IEquatable<int>
Implements
Inherited Members
Extension Methods

Properties

IsBlank

Is the type of value Blank?

public bool IsBlank { get; }

Property Value

bool

IsBoolean

Is the type of value Boolean?

public bool IsBoolean { get; }

Property Value

bool

IsDateTime

Is the type of value DateTime?

public bool IsDateTime { get; }

Property Value

bool

IsError

Is the type of value Error?

public bool IsError { get; }

Property Value

bool

IsNumber

Is the type of value Number?

public bool IsNumber { get; }

Property Value

bool

IsText

Is the type of value Text?

public bool IsText { get; }

Property Value

bool

IsTimeSpan

Is the type of value TimeSpan?

public bool IsTimeSpan { get; }

Property Value

bool

IsUnifiedNumber

Is the value Number or DateTime or TimeSpan.

public bool IsUnifiedNumber { get; }

Property Value

bool

Type

Type of the value.

public XLDataType Type { get; }

Property Value

XLDataType

Methods

Equals(Blank)

public bool Equals(Blank other)

Parameters

other Blank

Returns

bool

Equals(XLCellValue)

public bool Equals(XLCellValue other)

Parameters

other XLCellValue

Returns

bool

Equals(XLError)

public bool Equals(XLError other)

Parameters

other XLError

Returns

bool

Equals(bool)

public bool Equals(bool other)

Parameters

other bool

Returns

bool

Equals(DateTime)

public bool Equals(DateTime other)

Parameters

other DateTime

Returns

bool

Equals(double)

public bool Equals(double other)

Parameters

other double

Returns

bool

Equals(int)

public bool Equals(int other)

Parameters

other int

Returns

bool

Equals(object)

public override bool Equals(object obj)

Parameters

obj object

Returns

bool

Equals(string)

public bool Equals(string other)

Parameters

other string

Returns

bool

Equals(TimeSpan)

public bool Equals(TimeSpan other)

Parameters

other TimeSpan

Returns

bool

FromObject(object, IFormatProvider)

Creates an XLCellValue from an object. If the type of the object has an implicit conversion operator then it is used. Otherwise, the ToString(object, IFormatProvider) method is used to convert the provided object to a string.

The following types and their nullable counterparts are supported without requiring to be converted to a string:
public static XLCellValue FromObject(object obj, IFormatProvider provider = null)

Parameters

obj object

The object to convert.

provider IFormatProvider

An object that supplies culture-specific formatting information.

Returns

XLCellValue

An XLCellValue representation of the object.

GetBlank()

If the value is of type Blank, return Value, otherwise throw InvalidCastException.

public Blank GetBlank()

Returns

Blank

GetBoolean()

If the value is of type Boolean, return logical, otherwise throw InvalidCastException.

public bool GetBoolean()

Returns

bool

GetDateTime()

If the value is of type DateTime, return date time, otherwise throw InvalidCastException.

public DateTime GetDateTime()

Returns

DateTime

GetError()

If the value is of type Error, return error, otherwise throw InvalidCastException.

public XLError GetError()

Returns

XLError

GetHashCode()

public override int GetHashCode()

Returns

int

GetNumber()

If the value is of type Number, return number, otherwise throw InvalidCastException.

public double GetNumber()

Returns

double

GetText()

If the value is of type Text, return text, otherwise throw InvalidCastException.

public string GetText()

Returns

string

GetTimeSpan()

If the value is of type TimeSpan, return time span, otherwise throw InvalidCastException.

public TimeSpan GetTimeSpan()

Returns

TimeSpan

GetUnifiedNumber()

Get a number, either directly from type number or from serialized time span or serialized date time.

public double GetUnifiedNumber()

Returns

double

Exceptions

InvalidCastException

If type is not Number or DateTime or TimeSpan.

ToString()

Return text representation of a value in current culture.

public override string ToString()

Returns

string

ToString(CultureInfo)

Return text representation of a value in the specified culture.

public string ToString(CultureInfo culture)

Parameters

culture CultureInfo

Returns

string

TryConvert(out Blank)

Try to convert the value to a Blank and return it. Method succeeds, when value is

public bool TryConvert(out Blank value)

Parameters

value Blank

Returns

bool

TryConvert(out bool)

Try to convert the value to a Boolean and return it. Method succeeds, when value is

  • Type Boolean.
  • Type Number, then the value of 0 means false and any other value is true.
  • Type Text and the value is TRUE or FALSE (case insensitive). Note that calc engine generally doesn't coerce text to logical (e.g. arithmetic operations), though it happens in most function arguments (e.g. IF or AND).
public bool TryConvert(out bool value)

Parameters

value bool

Returns

bool

TryConvert(out DateTime)

Try to convert the value to a DateTime and return it. Method succeeds, when value is

  • Type DateTime.
  • Type Number and when the number is interpreted is a serial date time, it falls within the DateTime range.
  • Type TimeSpan and when the number is interpreted is a serial date time, it falls within the DateTime range.
public bool TryConvert(out DateTime value)

Parameters

value DateTime

Returns

bool

TryConvert(out double, CultureInfo)

Try to convert the value to a Number and return it.

  • Double value - return the value.
  • Boolean value - return the 0 for TRUE and 1 for FALSE.
  • Text value - use the VALUE semantic to convert a text to a number.
  • DateTime value - return the serial date time number.
  • TimeSpan value - return the serial time span value.
public bool TryConvert(out double value, CultureInfo culture)

Parameters

value double

The converted value. Result is never infinity or NaN.

culture CultureInfo

The culture used to convert the value for texts.

Returns

bool

Remarks

Note that the coercion is current culture specific (e.g. decimal separators can differ).

TryConvert(out TimeSpan, CultureInfo)

Try to convert the value to a TimeSpan and return it. Method succeeds, when value is

  • Type TimeSpan.
  • Type Number, the number is interpreted is a time span date time.
  • Type Text and it can be parsed as a time span (accepts even hours over 24 hours).
public bool TryConvert(out TimeSpan value, CultureInfo culture)

Parameters

value TimeSpan

The converted value.

culture CultureInfo

The culture used to get time and decimal separators.

Returns

bool

TryGetText(out string)

Get a value, if it is a Text.

public bool TryGetText(out string value)

Parameters

value string

Returns

bool

True if value was retrieved, false otherwise.

Operators

explicit operator Blank(XLCellValue)

If the value is of type Blank, return Value, otherwise throw InvalidCastException.

public static explicit operator Blank(XLCellValue value)

Parameters

value XLCellValue

Returns

Blank

explicit operator XLError(XLCellValue)

If the value is of type Error, return error, otherwise throw InvalidCastException.

public static explicit operator XLError(XLCellValue value)

Parameters

value XLCellValue

Returns

XLError

explicit operator bool(XLCellValue)

If the value is of type Boolean, return logical, otherwise throw InvalidCastException.

public static explicit operator bool(XLCellValue value)

Parameters

value XLCellValue

Returns

bool

explicit operator double(XLCellValue)

If the value is of type Number, return number, otherwise throw InvalidCastException.

public static explicit operator double(XLCellValue value)

Parameters

value XLCellValue

Returns

double

explicit operator string(XLCellValue)

If the value is of type Text, return text, otherwise throw InvalidCastException.

public static explicit operator string(XLCellValue value)

Parameters

value XLCellValue

Returns

string

implicit operator XLCellValue(Blank)

public static implicit operator XLCellValue(Blank blank)

Parameters

blank Blank

Returns

XLCellValue

implicit operator DateTime(XLCellValue)

If the value is of type DateTime, return date time, otherwise throw InvalidCastException.

public static implicit operator DateTime(XLCellValue value)

Parameters

value XLCellValue

Returns

DateTime

implicit operator TimeSpan(XLCellValue)

If the value is of type TimeSpan, return time span, otherwise throw InvalidCastException.

public static implicit operator TimeSpan(XLCellValue value)

Parameters

value XLCellValue

Returns

TimeSpan

implicit operator XLCellValue(XLError)

public static implicit operator XLCellValue(XLError error)

Parameters

error XLError

Returns

XLCellValue

implicit operator XLCellValue(bool)

public static implicit operator XLCellValue(bool logical)

Parameters

logical bool

Returns

XLCellValue

implicit operator XLCellValue(byte)

public static implicit operator XLCellValue(byte number)

Parameters

number byte

Returns

XLCellValue

implicit operator XLCellValue(DateTime)

public static implicit operator XLCellValue(DateTime dateTime)

Parameters

dateTime DateTime

Returns

XLCellValue

implicit operator XLCellValue(decimal)

public static implicit operator XLCellValue(decimal number)

Parameters

number decimal

Returns

XLCellValue

implicit operator XLCellValue(double)

public static implicit operator XLCellValue(double number)

Parameters

number double

Returns

XLCellValue

implicit operator XLCellValue(short)

public static implicit operator XLCellValue(short number)

Parameters

number short

Returns

XLCellValue

implicit operator XLCellValue(int)

public static implicit operator XLCellValue(int number)

Parameters

number int

Returns

XLCellValue

implicit operator XLCellValue(long)

public static implicit operator XLCellValue(long number)

Parameters

number long

Returns

XLCellValue

implicit operator XLCellValue(byte?)

public static implicit operator XLCellValue(byte? numberOrBlank)

Parameters

numberOrBlank byte?

Returns

XLCellValue

implicit operator XLCellValue(DateTime?)

public static implicit operator XLCellValue(DateTime? dateTimeOrBlank)

Parameters

dateTimeOrBlank DateTime?

Returns

XLCellValue

implicit operator XLCellValue(decimal?)

public static implicit operator XLCellValue(decimal? numberOrBlank)

Parameters

numberOrBlank decimal?

Returns

XLCellValue

implicit operator XLCellValue(double?)

public static implicit operator XLCellValue(double? numberOrBlank)

Parameters

numberOrBlank double?

Returns

XLCellValue

implicit operator XLCellValue(short?)

public static implicit operator XLCellValue(short? numberOrBlank)

Parameters

numberOrBlank short?

Returns

XLCellValue

implicit operator XLCellValue(int?)

public static implicit operator XLCellValue(int? numberOrBlank)

Parameters

numberOrBlank int?

Returns

XLCellValue

implicit operator XLCellValue(long?)

public static implicit operator XLCellValue(long? numberOrBlank)

Parameters

numberOrBlank long?

Returns

XLCellValue

implicit operator XLCellValue(sbyte?)

public static implicit operator XLCellValue(sbyte? numberOrBlank)

Parameters

numberOrBlank sbyte?

Returns

XLCellValue

implicit operator XLCellValue(float?)

public static implicit operator XLCellValue(float? numberOrBlank)

Parameters

numberOrBlank float?

Returns

XLCellValue

implicit operator XLCellValue(TimeSpan?)

public static implicit operator XLCellValue(TimeSpan? timeSpanOrBlank)

Parameters

timeSpanOrBlank TimeSpan?

Returns

XLCellValue

implicit operator XLCellValue(ushort?)

public static implicit operator XLCellValue(ushort? numberOrBlank)

Parameters

numberOrBlank ushort?

Returns

XLCellValue

implicit operator XLCellValue(uint?)

public static implicit operator XLCellValue(uint? numberOrBlank)

Parameters

numberOrBlank uint?

Returns

XLCellValue

implicit operator XLCellValue(ulong?)

public static implicit operator XLCellValue(ulong? numberOrBlank)

Parameters

numberOrBlank ulong?

Returns

XLCellValue

implicit operator XLCellValue(sbyte)

public static implicit operator XLCellValue(sbyte number)

Parameters

number sbyte

Returns

XLCellValue

implicit operator XLCellValue(float)

public static implicit operator XLCellValue(float number)

Parameters

number float

Returns

XLCellValue

implicit operator XLCellValue(string)

public static implicit operator XLCellValue(string text)

Parameters

text string

Returns

XLCellValue

implicit operator XLCellValue(TimeSpan)

public static implicit operator XLCellValue(TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

Returns

XLCellValue

implicit operator XLCellValue(ushort)

public static implicit operator XLCellValue(ushort number)

Parameters

number ushort

Returns

XLCellValue

implicit operator XLCellValue(uint)

public static implicit operator XLCellValue(uint number)

Parameters

number uint

Returns

XLCellValue

implicit operator XLCellValue(ulong)

public static implicit operator XLCellValue(ulong number)

Parameters

number ulong

Returns

XLCellValue