예제 #1
0
        public string ToString(double value, ExpressionFormat info = null)
        {
            string text;

            if (value < MIN_NUMBER || value > MAX_NUMBER)
            {
                text = ExcelValue.VALUE.ToString();
            }
            else
            {
                info ??= ExpressionFormat.General;
                var format = info.GetFormat(null);
                if (format.NeedsDate)
                {
                    var date = ExcelValue.FromDateSerial(value);
                    // Should start from beginning in order to use the overriden methods
                    if (date.HasValue)
                    {
                        text = ToString(date.Value, info);
                    }
                    else
                    {
                        text = ExcelValue.NA.ToString();
                    }
                }
                else
                {
                    text = string.Format(culture, format.Format, Convert.ToDecimal(value));
                }
            }
            return(text);
        }
예제 #2
0
 public void DateValue_FromDateSerial()
 {
     Assert.Null(ExcelValue.FromDateSerial(-1));
     Assert.Null(ExcelValue.FromDateSerial(0));
     Assert.Equal(new DateTime(1900, 1, 1, 6, 0, 0), ExcelValue.FromDateSerial(0.25));
     Assert.Equal(new DateTime(1900, 1, 1, 12, 0, 0), ExcelValue.FromDateSerial(0.5));
     Assert.Equal(new DateTime(1900, 1, 1, 18, 0, 0), ExcelValue.FromDateSerial(0.75));
     Assert.Equal(new DateTime(1900, 1, 1), ExcelValue.FromDateSerial(1));
     Assert.Equal(new DateTime(1900, 1, 2), ExcelValue.FromDateSerial(2));
     Assert.Equal(new DateTime(1900, 2, 28), ExcelValue.FromDateSerial(59));
     Assert.Equal(new DateTime(1900, 3, 1), ExcelValue.FromDateSerial(61));
     Assert.Equal(new DateTime(2008, 1, 1), ExcelValue.FromDateSerial(39448));
     Assert.Equal(new DateTime(2020, 5, 16), ExcelValue.FromDateSerial(43967));
 }