Ejemplo n.º 1
0
        public override string ToString(DateTime value, ExpressionFormat info)
        {
            // When running unit tests on github we receive "π.μ." instead of "πμ"
            var text = base.ToString(value, info);

            return(text?.Replace("π.μ.", "πμ").Replace("μ.μ.", "μμ"));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public virtual string ToString(DateTime value, ExpressionFormat info)
        {
            var format = info.GetFormat(ExpressionFormat.ShortDatePattern);

            if (format.NeedsDate)
            {
                return(string.Format(culture, format.Format, value));
            }
            // Should start from beginning in order to use the overriden methods
            var serial = ExcelValue.ToDateSerial(value);

            if (serial.HasValue)
            {
                return(ToString(serial.Value, info));
            }
            return(ExcelValue.NA.ToString());
        }
Ejemplo n.º 4
0
        private EvaluationResult Evaluate(string name, string cell, IEnumerable <ExcelFormulaToken> tokens, ExpressionScope scope, ExpressionFormat format)
        {
            var result = new EvaluationResult()
            {
                Name = name,
                Cell = cell
            };

            try
            {
                var queue           = new Queue <ExcelFormulaToken>(tokens);
                var excelExpression = new ExcelExpression();
                TraverseExpression(excelExpression, queue, scope);
                var operand = excelExpression.Evaluate(scope);
                scope.Set(cell ?? name, operand.Value);
                result.Value = operand.Value.InnerValue;
                result.Text  = operand.Value?.ToString(outputLang, format);
            }
            catch (Exception ex)
            {
                result.Error = ex.Message;
            }
            finally { }
            return(result);
        }
Ejemplo n.º 5
0
        protected EvaluationResult Evaluate(string name, string cell, string expression, ExpressionScope scope, ExpressionFormat format)
        {
            if (!expression.StartsWith("="))
            {
                expression = "=" + expression;
            }
            var excelFormula = new ExcelFormula(expression);
            var tokens       = excelFormula.OfType <ExcelFormulaToken>();

            return(Evaluate(name, cell, tokens, scope, format));
        }