Struct XLCellValue
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
XLCellValueto a concrete type. It is an equivalent ofGet*methods. TryConvertmethods 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
IsBoolean
Is the type of value Boolean?
public bool IsBoolean { get; }
Property Value
IsDateTime
Is the type of value DateTime?
public bool IsDateTime { get; }
Property Value
IsError
Is the type of value Error?
public bool IsError { get; }
Property Value
IsNumber
Is the type of value Number?
public bool IsNumber { get; }
Property Value
IsText
Is the type of value Text?
public bool IsText { get; }
Property Value
IsTimeSpan
Is the type of value TimeSpan?
public bool IsTimeSpan { get; }
Property Value
IsUnifiedNumber
public bool IsUnifiedNumber { get; }
Property Value
Type
Type of the value.
public XLDataType Type { get; }
Property Value
Methods
Equals(Blank)
public bool Equals(Blank other)
Parameters
otherBlank
Returns
Equals(XLCellValue)
public bool Equals(XLCellValue other)
Parameters
otherXLCellValue
Returns
Equals(XLError)
public bool Equals(XLError other)
Parameters
otherXLError
Returns
Equals(bool)
public bool Equals(bool other)
Parameters
otherbool
Returns
Equals(DateTime)
public bool Equals(DateTime other)
Parameters
otherDateTime
Returns
Equals(double)
public bool Equals(double other)
Parameters
otherdouble
Returns
Equals(int)
public bool Equals(int other)
Parameters
otherint
Returns
Equals(object)
public override bool Equals(object obj)
Parameters
objobject
Returns
Equals(string)
public bool Equals(string other)
Parameters
otherstring
Returns
Equals(TimeSpan)
public bool Equals(TimeSpan other)
Parameters
otherTimeSpan
Returns
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
objobjectThe object to convert.
providerIFormatProviderAn 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
GetBoolean()
If the value is of type Boolean, return logical, otherwise throw InvalidCastException.
public bool GetBoolean()
Returns
GetDateTime()
If the value is of type DateTime, return date time, otherwise throw InvalidCastException.
public DateTime GetDateTime()
Returns
GetError()
If the value is of type Error, return error, otherwise throw InvalidCastException.
public XLError GetError()
Returns
GetHashCode()
public override int GetHashCode()
Returns
GetNumber()
If the value is of type Number, return number, otherwise throw InvalidCastException.
public double GetNumber()
Returns
GetText()
If the value is of type Text, return text, otherwise throw InvalidCastException.
public string GetText()
Returns
GetTimeSpan()
If the value is of type TimeSpan, return time span, otherwise throw InvalidCastException.
public TimeSpan GetTimeSpan()
Returns
GetUnifiedNumber()
Get a number, either directly from type number or from serialized time span or serialized date time.
public double GetUnifiedNumber()
Returns
Exceptions
ToString()
Return text representation of a value in current culture.
public override string ToString()
Returns
ToString(CultureInfo)
Return text representation of a value in the specified culture.
public string ToString(CultureInfo culture)
Parameters
cultureCultureInfo
Returns
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
valueBlank
Returns
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
0meansfalseand any other value istrue. - Type Text and the value is
TRUEorFALSE(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.IForAND).
public bool TryConvert(out bool value)
Parameters
valuebool
Returns
TryConvert(out DateTime)
Try to convert the value to a DateTime and return it. Method succeeds, when value is
public bool TryConvert(out DateTime value)
Parameters
valueDateTime
Returns
TryConvert(out double, CultureInfo)
Try to convert the value to a Number and return it.
- Double value - return the value.
- Boolean value - return the
0forTRUEand1forFALSE. - Text value - use the
VALUEsemantic 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
valuedoubleThe converted value. Result is never
infinityorNaN.cultureCultureInfoThe culture used to convert the value for texts.
Returns
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
public bool TryConvert(out TimeSpan value, CultureInfo culture)
Parameters
valueTimeSpanThe converted value.
cultureCultureInfoThe culture used to get time and decimal separators.
Returns
TryGetText(out string)
Get a value, if it is a Text.
public bool TryGetText(out string value)
Parameters
valuestring
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
valueXLCellValue
Returns
explicit operator XLError(XLCellValue)
If the value is of type Error, return error, otherwise throw InvalidCastException.
public static explicit operator XLError(XLCellValue value)
Parameters
valueXLCellValue
Returns
explicit operator bool(XLCellValue)
If the value is of type Boolean, return logical, otherwise throw InvalidCastException.
public static explicit operator bool(XLCellValue value)
Parameters
valueXLCellValue
Returns
explicit operator double(XLCellValue)
If the value is of type Number, return number, otherwise throw InvalidCastException.
public static explicit operator double(XLCellValue value)
Parameters
valueXLCellValue
Returns
explicit operator string(XLCellValue)
If the value is of type Text, return text, otherwise throw InvalidCastException.
public static explicit operator string(XLCellValue value)
Parameters
valueXLCellValue
Returns
implicit operator XLCellValue(Blank)
public static implicit operator XLCellValue(Blank blank)
Parameters
blankBlank
Returns
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
valueXLCellValue
Returns
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
valueXLCellValue
Returns
implicit operator XLCellValue(XLError)
public static implicit operator XLCellValue(XLError error)
Parameters
errorXLError
Returns
implicit operator XLCellValue(bool)
public static implicit operator XLCellValue(bool logical)
Parameters
logicalbool
Returns
implicit operator XLCellValue(byte)
public static implicit operator XLCellValue(byte number)
Parameters
numberbyte
Returns
implicit operator XLCellValue(DateTime)
public static implicit operator XLCellValue(DateTime dateTime)
Parameters
dateTimeDateTime
Returns
implicit operator XLCellValue(decimal)
public static implicit operator XLCellValue(decimal number)
Parameters
numberdecimal
Returns
implicit operator XLCellValue(double)
public static implicit operator XLCellValue(double number)
Parameters
numberdouble
Returns
implicit operator XLCellValue(short)
public static implicit operator XLCellValue(short number)
Parameters
numbershort
Returns
implicit operator XLCellValue(int)
public static implicit operator XLCellValue(int number)
Parameters
numberint
Returns
implicit operator XLCellValue(long)
public static implicit operator XLCellValue(long number)
Parameters
numberlong
Returns
implicit operator XLCellValue(byte?)
public static implicit operator XLCellValue(byte? numberOrBlank)
Parameters
numberOrBlankbyte?
Returns
implicit operator XLCellValue(DateTime?)
public static implicit operator XLCellValue(DateTime? dateTimeOrBlank)
Parameters
dateTimeOrBlankDateTime?
Returns
implicit operator XLCellValue(decimal?)
public static implicit operator XLCellValue(decimal? numberOrBlank)
Parameters
numberOrBlankdecimal?
Returns
implicit operator XLCellValue(double?)
public static implicit operator XLCellValue(double? numberOrBlank)
Parameters
numberOrBlankdouble?
Returns
implicit operator XLCellValue(short?)
public static implicit operator XLCellValue(short? numberOrBlank)
Parameters
numberOrBlankshort?
Returns
implicit operator XLCellValue(int?)
public static implicit operator XLCellValue(int? numberOrBlank)
Parameters
numberOrBlankint?
Returns
implicit operator XLCellValue(long?)
public static implicit operator XLCellValue(long? numberOrBlank)
Parameters
numberOrBlanklong?
Returns
implicit operator XLCellValue(sbyte?)
public static implicit operator XLCellValue(sbyte? numberOrBlank)
Parameters
numberOrBlanksbyte?
Returns
implicit operator XLCellValue(float?)
public static implicit operator XLCellValue(float? numberOrBlank)
Parameters
numberOrBlankfloat?
Returns
implicit operator XLCellValue(TimeSpan?)
public static implicit operator XLCellValue(TimeSpan? timeSpanOrBlank)
Parameters
timeSpanOrBlankTimeSpan?
Returns
implicit operator XLCellValue(ushort?)
public static implicit operator XLCellValue(ushort? numberOrBlank)
Parameters
numberOrBlankushort?
Returns
implicit operator XLCellValue(uint?)
public static implicit operator XLCellValue(uint? numberOrBlank)
Parameters
numberOrBlankuint?
Returns
implicit operator XLCellValue(ulong?)
public static implicit operator XLCellValue(ulong? numberOrBlank)
Parameters
numberOrBlankulong?
Returns
implicit operator XLCellValue(sbyte)
public static implicit operator XLCellValue(sbyte number)
Parameters
numbersbyte
Returns
implicit operator XLCellValue(float)
public static implicit operator XLCellValue(float number)
Parameters
numberfloat
Returns
implicit operator XLCellValue(string)
public static implicit operator XLCellValue(string text)
Parameters
textstring
Returns
implicit operator XLCellValue(TimeSpan)
public static implicit operator XLCellValue(TimeSpan timeSpan)
Parameters
timeSpanTimeSpan
Returns
implicit operator XLCellValue(ushort)
public static implicit operator XLCellValue(ushort number)
Parameters
numberushort
Returns
implicit operator XLCellValue(uint)
public static implicit operator XLCellValue(uint number)
Parameters
numberuint
Returns
implicit operator XLCellValue(ulong)
public static implicit operator XLCellValue(ulong number)
Parameters
numberulong