ReoGrid icon indicating copy to clipboard operation
ReoGrid copied to clipboard

ConvertData<T>(object data, out T value) System.OverflowException

Open Ramon403 opened this issue 6 years ago • 1 comments

sheet.GetCellData<decimal>(addrs);

Get the value of a formula cell. Formula (A/B) return NaN because B is 0. Runtime throws an exception: System. Overflow Exception: Value was either too large or too small for a Decimal.

I found that the error occurred in the class: Unvell. ReoGrid. Utility. CellUtility

public static bool ConvertData<T>(object data, out T value)
{
    .....
     value = (T)Convert.ChangeType(data, typeof(T));
     return true;
}

Is it possible to change it to the following:

public static bool ConvertData<T>(object data, out T value)
{
     ...
    if (data is double)
    {
       if (double.IsNaN((double)data) || double.IsInfinity((double)data))
          {
                    data = 0;
          }
    }
     value = (T)Convert.ChangeType(data, typeof(T));
     return true;
}

Ramon403 avatar Feb 25 '19 03:02 Ramon403

@Ramon403 Thanks! I know this is old but could you please make a pull request for this?

jingwood avatar Jan 12 '23 04:01 jingwood